I can't find a way to disable the mouse look script when I open a menu. My screen cursor is locked then unlocked when you open the menu.
Code Menu 1 ( Only the parts of the script you need to see ;) ) :
private var playerCML : MouseLook;
private var playerML : MouseLook;
function Start()
{
playerGUI = GameObject.Find("First Person Controller").GetComponent(PlayerGUI);
playerCML = GameObject.Find("Main Camera").GetComponent(MouseLook);
playerML = GameObject.Find("First Person Controller").GetComponent(MouseLook);
}
if(showGUI == true)
{
playerCML.enabled = false;
playerML.enabled = false;
GameObject.Find("First Person Controller").GetComponent(FPSInputController).enabled = false;
GameObject.Find("FPSArms_Axe@Idle").GetComponent(PlayerControl).enabled = false;
Screen.lockCursor = false;
}
if(showGUI == false)
{
playerCML.enabled = true;
playerML.enabled = true;
GameObject.Find("First Person Controller").GetComponent(FPSInputController).enabled = true;
GameObject.Find("FPSArms_Axe@Idle").GetComponent(PlayerControl).enabled = true;
Screen.lockCursor = true;
}
the last part is in the update function(you can't see it
Whole Script:
#pragma strict
var menuSkin : GUISkin;
var wood : int = 0;
var stone : int = 0;
var clay : int = 0;
var rawMeat : int = 0;
var cookedMeat : int = 0;
var bottle : int = 0;
var water : int = 0;
var bandage : int = 0;
private var showGUI : boolean = false;
private var playerGUI : PlayerGUI;
var minimum : int = 0;
private var playerCML : MouseLook;
private var playerML : MouseLook;
function Start()
{
playerGUI = GameObject.Find("First Person Controller").GetComponent(PlayerGUI);
playerCML = GameObject.Find("Main Camera").GetComponent(MouseLook);
playerML = GameObject.Find("First Person Controller").GetComponent(MouseLook);
}
function Update()
{
if(wood <= 0)
{
wood = minimum;
}
if(stone <= 0)
{
stone = minimum;
}
if(clay <= 0)
{
clay = minimum;
}
if(rawMeat <= 0)
{
rawMeat = minimum;
}
if(cookedMeat <= 0)
{
cookedMeat = minimum;
}
if(bottle <= 0)
{
bottle = minimum;
}
if(water <= 0)
{
water = minimum;
}
if(bandage <= 0)
{
bandage = minimum;
}
if(Input.GetKeyDown("i"))
{
showGUI = !showGUI;
}
if(showGUI == true)
{
playerCML.enabled = false;
playerML.enabled = false;
GameObject.Find("First Person Controller").GetComponent(FPSInputController).enabled = false;
GameObject.Find("FPSArms_Axe@Idle").GetComponent(PlayerControl).enabled = false;
Screen.lockCursor = false;
}
if(showGUI == false)
{
playerCML.enabled = true;
playerML.enabled = true;
GameObject.Find("First Person Controller").GetComponent(FPSInputController).enabled = true;
GameObject.Find("FPSArms_Axe@Idle").GetComponent(PlayerControl).enabled = true;
Screen.lockCursor = true;
}
}
function OnGUI()
{
if(showGUI == true)
{
GUI.skin = menuSkin;
GUI.BeginGroup(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 150, 300, 300));
GUI.Box(Rect(0, 0, 300, 300), "Inventory");
GUI.Label(Rect(20, 50, 100, 50), "Wood");
GUI.Box(Rect(80, 50, 30, 20), "" + wood);
GUI.Label(Rect(100, 50, 100, 50), "Stone");
GUI.Box(Rect(160, 50, 30, 20), "" + stone);
GUI.Label(Rect(180, 50, 100, 50), "Rope");
GUI.Box(Rect(240, 50, 30, 20), "" + clay);
GUI.Label(Rect(10, 100, 100, 50), "Raw Meat");
GUI.Box(Rect(110, 100, 30, 20), "" + rawMeat);
GUI.Label(Rect(10, 130, 100, 50), "Empty Bottles");
GUI.Box(Rect(110, 130, 30, 20), "" + bottle);
GUI.Label(Rect(10, 160, 100, 50), "Cooked Meat");
GUI.Box(Rect(110, 160, 30, 20), "" + cookedMeat);
if(GUI.Button(Rect(150, 100, 120, 40), "Eat Meat?"))
{
cookedMeat--;
if(cookedMeat > 0)
{
Eat();
}
}
GUI.Label(Rect(10, 190, 100, 50), "Bottled Water");
GUI.Box(Rect(110, 190, 30, 20), "" + water);
if(GUI.Button(Rect(150, 150, 120, 40), "Drink Water?"))
{
water--;
if(water > 0)
{
Drink();
}
}
GUI.Label(Rect(10, 220, 100, 50), "Bandage");
GUI.Box(Rect(110, 220, 30, 20), "" + bandage);
if(GUI.Button(Rect(150, 200, 120, 40), "Use Bandage?"))
{
bandage--;
if(bandage > 0)
{
Heal();
}
}
GUI.EndGroup();
}
}
function Eat()
{
playerGUI.hungerBarDisplay += 0.2;
}
function Drink()
{
playerGUI.thirstBarDisplay += 0.2;
}
function Heal()
{
playerGUI.healthBarDisplay += 0.3;
}
function Reset()
{
wood = minimum;
stone = minimum;
clay = minimum;
rawMeat = minimum;
cookedMeat = minimum;
bottle = minimum;
water = minimum;
bandage = minimum;
}
Menu 2:
function Update()
{
if(Input.GetKeyDown("c"))
{
showGUI = !showGUI;
}
if(showGUI == true)
{
Time.timeScale = 0;
player.GetComponent(FPSInputController).enabled = false;
player.GetComponent(MouseLook).enabled = false;
mainCamera.GetComponent(MouseLook).enabled = false;
arms.GetComponent(PlayerControl).enabled = false;
Screen.lockCursor = false;
}
if(showGUI == false)
{
Time.timeScale = 0;
player.GetComponent(FPSInputController).enabled = true;
player.GetComponent(MouseLook).enabled = true;
mainCamera.GetComponent(MouseLook).enabled = true;
arms.GetComponent(PlayerControl).enabled = true;
Screen.lockCursor = true;
}
}
Whole Script:
#pragma strict
var MenuSkin : GUISkin;
var player : GameObject;
var mainCamera : GameObject;
var arms : GameObject;
var campfireIcon : Texture;
var tentIcon : Texture;
var spareIcon : Texture;
var campfire : GameObject;
var tent : GameObject;
var spare : GameObject;
private var showGUI : boolean = false;
private var invScript : Inv;
function Start()
{
invScript = GetComponent(Inv);
}
function Update()
{
if(Input.GetKeyDown("c"))
{
showGUI = !showGUI;
}
if(showGUI == true)
{
Time.timeScale = 0;
player.GetComponent(FPSInputController).enabled = false;
player.GetComponent(MouseLook).enabled = false;
mainCamera.GetComponent(MouseLook).enabled = false;
arms.GetComponent(PlayerControl).enabled = false;
Screen.lockCursor = false;
}
if(showGUI == false)
{
Time.timeScale = 0;
player.GetComponent(FPSInputController).enabled = true;
player.GetComponent(MouseLook).enabled = true;
mainCamera.GetComponent(MouseLook).enabled = true;
arms.GetComponent(PlayerControl).enabled = true;
Screen.lockCursor = true;
}
}
function OnGUI()
{
if(showGUI == true)
{
GUI.skin = MenuSkin;
GUI.BeginGroup(new Rect(Screen.width / 2 - 150, Screen.height / 2 -150, 300, 300));
GUI.Box(Rect(0, 0, 300, 300), "Crafting");
if(GUI.Button(Rect(35, 55, 50, 50), GUIContent (campfireIcon, "Build a campfire")))
{
if(invScript.wood >= 6 && invScript.stone >= 3)
{
showGUI = false;
campfire.SetActive(true);
invScript.wood -= 6;
invScript.stone -= 3;
}
}
if(GUI.Button(Rect(35, 125, 50, 50), GUIContent (tentIcon, "Build a tent")))
{
if(invScript.clay >= 10 && invScript.wood >= 3)
{
showGUI = false;
tent.SetActive(true);
invScript.clay -= 10;
invScript.wood -= 3;
}
}
if(GUI.Button(Rect(35, 195, 50, 50), GUIContent (spareIcon, "Build a spare")))
{
if(invScript.clay >= 0 && invScript.wood >= 0)
{
showGUI = false;
spare.SetActive(true);
invScript.wood -= 0;
invScript.stone -= 0;
}
}
//Second Column
if(GUI.Button(Rect(125, 55, 50, 50), GUIContent (spareIcon, "Build a spare")))
{
if(invScript.wood >= 0 && invScript.stone >= 0)
{
showGUI = false;
spare.SetActive(true);
invScript.wood -= 6;
invScript.stone -= 3;
}
}
if(GUI.Button(Rect(125, 125, 50, 50), GUIContent (spareIcon, "Build a spare")))
{
if(invScript.clay >= 0 && invScript.wood >= 0)
{
showGUI = false;
spare.SetActive(true);
invScript.clay -= 10;
invScript.wood -= 3;
}
}
if(GUI.Button(Rect(125, 195, 50, 50), GUIContent (spareIcon, "Build a spare")))
{
if(invScript.clay >= 0 && invScript.wood >= 0)
{
showGUI = false;
spare.SetActive(true);
invScript.wood -= 0;
invScript.stone -= 0;
}
}
GUI.Label(Rect(90, 250, 200, 40), GUI.tooltip);
GUI.EndGroup();
}
}
Thankyou! None of these scripts work I have tried different methods.
↧