Answers for "unity while loop"

C#
4

for loop unity

for (int i = 0; i < 50; i++)
{
	//Do something 50 times
}
Posted by: Guest on June-17-2020
1

unity while loop

//you can do:

int count = 0;

while(count < 10)
{
  print("This text will run 10 times!!!, this is: " + count);
}

//for infinite loop (use update instead)
while(true)
{
 print("Spam"); 
}
Posted by: Guest on April-22-2021
1

how to make a loop in unity

public bool one = true;
public bool two = false;
public float delay = 2f;

void Update()
{
  if(one == true)               // the delay at the top is the amount
  {                             // of seconds until you call the Function
    Invoke("One", delay);       // again so if the delay were 3f it
    one = false;                // whould be three seconds until you call
  }                             // the Function again
  if(two == true)
  {
    Invoke("Two", delay);
    two = false;
  }
}
void One()
{
  two = true;                   // where it says "FunctionName" is the name
  FunctionName();               // of the function you want to be called
}                               // for example if your function is called
void Two()                      // "void Move()" then it whould be "Move"
{                               // instead
  one = true;
  FunctionName();
}
Posted by: Guest on January-06-2021

C# Answers by Framework

Browse Popular Code Answers by Language