# How can I do something only once In Update function?

when I do something In Update():

void Update(){
Debug.Log("Hello World");
}


I have this output:

Hello World
Hello World
.
.
.
Hello World


but Instead of printing manytimes I need a way that print Hello World once.

• It's not clear what you are trying to do or what is not working for you. Can you explain in more detail what behaviour you want, and what behaviour you are observing instead? Right now that second if test looks funny, testing for a value of Frequent that the previous section would have already changed. Oct 24 '15 at 13:48

If you want your code to run once you can simple solve it by having a boolean that checks if your code has run before and then simply do or don't do it. (with a if-statement):

bool isDone = false;

void Update() {
if (!isDone) {
// put your code that runs once here
isDone = true;
}
}


This way, that piece of code that is in the Update() method will only be called once because of that boolean.