- Home /
Update Just Once
I can't figure out this, I know it's been answered around a lot, but trying to figure out if an object is alive or not (exists in the scene or not) in order to activate another object if so, I did this. Obviously it works, the only problem is it keeps working :)
function Update () {
if (GameObject.Find (ObjectiveName) != null) {
Debug.Log("STILL HERE");
} else {
Debug.Log("DEAD");
messageObject.gameObject.SetActive(true);
messageText.text = myString;
}
}
Answer by wesleywh · Jul 16, 2015 at 08:04 PM
What you could do is add a boolean to check for as well to make sure that it is only done once. Here is how I might do it:
private var doOnce:boolean = true;
function Update () {
if (GameObject.Find (ObjectiveName) != null) {
doOnce = true;
} else {
if(doOnce == true){
doOnce = false;
messageObject.gameObject.SetActive(true);
messageText.text = myString;
}
}
}
Answer by CaKeMeaT · Jul 16, 2015 at 08:03 PM
It looks as if it should work, maybe use a bool to explicitely control the condition
if (!IsThisThingAlreadyAssigned) { ObjectiveTHing = GameObject.Find (ObjectiveName); IsThisThingAlreadyAssigned = true;
}
Your answer
Follow this Question
Related Questions
How to run a update function once 3 Answers
Calling a function only once in Update 6 Answers
Call A Function At A Certain Time 1 Answer
Play sound ONCE! 3 Answers