- Home /
v.important : Choose one from functions to execute !!
Hello guys , i have two functions (RotateRight & RotateLeft), please how i can choose one of two functions to execute one of them randomly when the script executing !!
i try this code :
var functions = [RotateRight,RotateLeft];
function Update(){
if(Timer1>=2){
functions[Random.Range(0,functions.Length)]();
}
if(Timer1>=5){
TranslateBack = false ;
TasadomDone = true ;
Timer1=0 ;
}
}
the problem here that the script execute this : functions[Random.Range(0,functions.Length)](); and still choose between the two functions without execute the next Lines . where id the problem here ??! i want every time choose one of two functions only , then executing the next lines . sorry for question , i,m a beginner , and sorry for my english :(
Answer by orb · Sep 08, 2014 at 09:35 AM
You're checking if the number is larger than 1, followed by checking if the number is larger than 4. Both will be true at the same time if the second is true. You should either reverse the order (check for the largest numbers first).
Your answer

Follow this Question
Related Questions
How do I call a function containing a while loop, inside the update function? 2 Answers
Do you know the solution of this probelm? (Problem is in the details) 0 Answers
Calling a function from a different script on the same object 1 Answer
How to use UnityAdsVideoCompleted(); 0 Answers
Is there any way to check which method called a certain other method? 1 Answer