- Home /
This question was
closed May 14, 2021 at 07:07 AM by
dick for the following reason:
Other
Question by
dick · May 13, 2021 at 11:37 PM ·
scripting problemgameobjectscriptingbasicssetactivebool
Simple GameObject Hide/Unhide with bool!!!
Hello,
In my script, a bool turns true whenever a Key is held down in the update, and turns false when it's not held down. (this works)
void Update()
{
myBool = Input.GetKey(KeyCode.G);
}
However, when i want a GameObject to be SetActive according to that bool, it won't work and the bool stays true, even when the key is let go. This is what i put in for turning on the GO in the script
GO.SetActive(!Input.GetKey(G));
Why is this? Can someone help with the GO being SetActive when the key is being held down and vice-versa? Thank you!!
Comment
Hello, would you please give more info where is this script attached or how to recreate the situation. I hope the G is the KeyCode variable. I gave a try with this approach and it is working, so would like to know your setup.