I have an array learnnum that looks like [0,1,1,0,1,1,1,1,0].
I need to basically ask the user for an input Left Mouse Button or Right Mouse Button. If Left, then the values of learnnum of [i] is flipped, else nothing happens. I only do this for i=1,3,5,7. I have written the below code, but it does not work properly, instead of going for all the 4 conditions… it directly goes to 4. It seems that it is not waiting for the input conditions… Is there any way I can correct this?
function changeNumba(i)
{ //check1=true;
print ("PRINTT "+check1);
while(!Input.GetButtonDown("Fire1") && !Input.GetButtonDown("Fire2"))
{
if(Input.GetButtonDown("Fire1"))
{
check1++;
}
if(Input.GetButtonDown("Fire2"))
{
learnednum[i]=0 ? 1 : 0;
check1++;
}
}
}
function changelearn()
{
//FIRST STEP
//if(check1)
if(move1==9 && check1==0)
{changeNumba(1);
}
//SECOND STEP
if(move1==9 && check1==1)
{changeNumba(3);
}
if(move1==9 && check1==2)
{changeNumba(5);
}
if(move1==9 && check1==3)
{changeNumba(7);
}
}
var check1=0;
//1,3,5,7
function Update () {
if(move1==9)//this is just a game condition. Do not bother about it.
{
changelearn();
}
}
from looking at the unity script api:
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButtonDown.html
you should not have a while() loop inside of your Update() method.
change changeNumba() as follows: