3
\$\begingroup\$

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.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Oct 24 '15 at 13:48
2
\$\begingroup\$

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.

Let me know if this answers your question.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.