Hey I have a script that goes like this,
if (balldeath.death == true) {
GameObject.Find (“Canvas”).SetActive(true);
}
but unfortunately it doesn’t work, if i set it to false it does work.
P.S. i’m using UnityEngine.UI
thanks
Hey I have a script that goes like this,
if (balldeath.death == true) {
GameObject.Find (“Canvas”).SetActive(true);
}
but unfortunately it doesn’t work, if i set it to false it does work.
P.S. i’m using UnityEngine.UI
thanks
GameObject.Find() will not find objects that are not active. That is, it will ONLY find objects that are active and in the scene.
Any alternatives?
Depending on the structure of your scene you could keep a reference to the Canvas you’re wanting to enable as a member of a game object (perhaps on the object you’re calling Find from now).
To do this create a public member like:
public Canvas canvasReference;
And then in the editor drag the canvas object onto that field in the inspector.
Then rather than use Find, just do:
canvasReference.SetActive(true);
Another option would be to have the object active in the scene and then do a Find in Start() to get the reference and set it inactive but save the reference in a private class member for when you want to make it active.
There are lots of options but all essentially revolve around getting a reference and storing it somewhere.
I don’t know why but i did what you said but i still can’t get it to work…
Sorry but I can’t help with “can’t get it to work”. You’ll need to show your code (in code blocks please) and explain what you have done and what “didn’t work” (ie what errors did you get, what did happen, etc).
Oh, now i got it! Thanks! your method works!
Excellent!