Setting a gameObject active when a button is pressed
I would like a menu to appear in my left hand, if I am holding the left touch controller trigger, and I have looked through countless documentation on how to set active. Is there a different function that I should be using, or is the script simply not recognizing that I'm pressing the button.
(Script is placed on the actual menu gameObject, which has another script (working) to bind it to my left hand)
public OVRInput.Button menu = OVRInput.Button.PrimaryIndexTrigger;
private bool activity;
void Start () {
activity = false;
}
void Update () {
gameObject.SetActive(activity);
if (OVRInput.Get (menu)) {
activity = true;
} else {
activity = false;
}
}
}
Answer by HostlerMathisTyler · Apr 21, 2017 at 01:06 PM
I've resolved the issue. I wasn't aware that deactivating an object also deactivated the script. I'm just going to place this script on a game controller that is always active.
Answer by SrGonzalez · Apr 21, 2017 at 12:07 PM
by putting "gameObject" you are interacting with the object the script is do something like that:
public OVRInput.Button menu = OVRInput.Button.PrimaryIndexTrigger;
private bool activity;
public GameObject obj; //here the object you want to disable
void Start () {
activity = false;
}
void Update () {
obj.SetActive(activity); //here disables the obj
if (OVRInput.Get (menu)) {
activity = true;
} else {
activity = false;
}
}
}
Hey, so the script is already placed into the menu object, so isn't adding this just recursive? I thought "gameObject" references the object that the script is on.