I have a piece of code that is trying to get the player to jump between 2 boxes only Cube 1 (position on left side) and Cube 2 (on right side) by tapping.
The issue with the Move() function is that it starts jumping from Cube 1 to Cube 2, then Cube 2 back to Cube 1, but from this point on, the player jumps from Cube 1 to the left side the opposite of Cube 2.
The jump functions are working, but I think the logic is incorrect.
Move:
void Move(){
int i = 0;
while ((isGrounded == true) && (i < 10)) {
if(atCube1 == true){
JumpRight();
}
if(atCube2 == true){
JumpLeft();
}
i++;
}
}
OnCollisionEnter:
void OnCollisionEnter (Collision col)
{
Debug.Log("OnCollisionEnter");
if (col.gameObject.name == "Cube 1"){
Debug.Log ("++++++ C U B E 1 H I T ++++++++");
atCube1 = true;
isGrounded = true;
}
if(col.gameObject.name == "Cube 2"){
Debug.Log ("Cube 2 hit");
atCube2 = true;
isGrounded = true;
}
}
== true. 2) what ifatCube1andatCube2are both true? - Wai Ha LeeatCube2to false when on cube 1 andatCube1to false when on cube 2. - Wai Ha Lee