I have a “Canvas” gameObject that contains my button. When the player presses the “E” Key, I want them to be able to deactivate and reactivate the menu (button). However, I can’t seem to deactivate it from another script. For example: This script is attatched to the FPS Controller. I can’t find a way to deactivate and reactivate the CanvasObject from another gameObject’s script. I have tried almost everything, and I’ve been googling for an hour. What am I doing wrong?
#pragma strict
var Money = 100;
public var GlassPrefab : Transform;
var Rotation;
var ShowBuildMenu = false;
var CanvasObject : Transform;
function Start () {
}
function Update () {
if(Input.GetKeyDown(KeyCode.E)){
ShowBuildMenu = !ShowBuildMenu;
//CanvasObject.gameObject.active = !CanvasObject.gameObject.active;
CanvasObject.enabled = ShowBuildMenu;
}
}
Gameobject something = gameobject.find("Canvas/Button"); something.setactive(true); hope this helps
– bodecTry deactivating the GameObject and not the Transform.
– Side