Hi All, I am a new user of Unity, I have one problem, I make a simple code for my project, but the script not found well,
function Update () {
if (!control.selectMouse){
gameObject.SetActive (true);
}
if (control.selectMouse){
gameObject.SetActive (false);
}
Ok, my problem is with SetActive, when I have Click on the boolean “selectMouse” the SetActive change of false correct, BUT when I have click again the SetActive not return to true! thanks
Once you turn off the gameObject, the Update functions will stop running. What you can do is this:
var target:GameObject;
function Update () {
if (!control.selectMouse){
target.SetActive (true);
}
if (control.selectMouse){
target.SetActive (false);
}
Attach this it another gameobject and assign the target. That way you are not enabling/disabling the object with the script.
Or in your case, you want SetActive to be the opposite of selectMouse, so this would be even cleaner :
gameObject.SetActive (!control.selectMouse);
In any case, this has no place in the Update function. I suggest you do some simple scripting tutorials, and post questions on Unity Answers as the forum is for discussions.
thank you both, I’ll try your advice, and I’ve really seen many hours of tutorials, but none were saying that the functions cease to happen once the gameobject has been disabled, today I learned something new, thanks to the two.
In a perfect world, everyone would search Unity Answers (as well as the Unity Script Reference) before posting, but this forum is still the quickest way to get answers to scripting questions.