hello there I’m trying to make an iPhone platform game and I have setup 3 GUI buttons. If you press them they will make the player can either move left right or jump. I have a strange problem with jumping though, every second jump or when a i’ve pressed the jump button 2, 4 , 10, 16 times my player barely jumps at all but if i’ve pressed it 1, 3 , 5 times it jumps it required jump height that i’ve set it to. Hope this makes sense. This problem is very strange and I don’t know why this is happening. Any help would be highly appreciated
The for GUI buttons :
#pragma strict
var isMovingLeft = false;
var isMovingRight = false;
var isJumping = false;
function OnGUI () {
if(GUI.RepeatButton(new Rect(300,250,80,50),"Left")){
isMovingLeft = true;
}else{
isMovingLeft = false;
}
if(GUI.RepeatButton(new Rect(400,250,80,50),"right")){
isMovingRight = true;
}else{
isMovingRight = false;
}
if(GUI.RepeatButton(new Rect(365,220,50,20),"jump")){
isJumping = true;
}else{
isJumping = false;
}
}
and for the player :
#pragma strict
var movement : Vector3 = Vector3.zero;
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
if (GameObject.Find("Camera").GetComponent(buttons).isMovingLeft){ //will check if true
transform.position -= Vector3.right * 2 * Time.deltaTime;
}
if (GameObject.Find("Camera").GetComponent(buttons).isMovingRight){ //will check if true
transform.position += Vector3.right * 2 * Time.deltaTime;
}
if (GameObject.Find("Camera").GetComponent(buttons).isJumping && controller.isGrounded){ //will check if true
movement.y += 13;
}
if(controller.isGrounded == false){
movement.y += Physics.gravity.y * Time.deltaTime;
}
controller.Move(movement * Time.deltaTime);
}
thanks