how can my player keep jumping wen it hit ground again?
I want to make my player to keep jumping wen it hit the ground a gain if I'm holding my button down, but right know it only jumps one for each time a click or hold the button . is for mobile divice.
this is my script
public enum type {LeftButton, RightButton, JumpButton,PouseButton};
public type buttonType;
public float jumpHeight = 0.0f, moveSpeed = 0.0f;
public GameObject playerObject = null;
public GUITexture buttonTexture = null;
private float myTouchDT = 0;
private Touch touch;
private bool isGrounded;
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.name == "ground")
isGrounded = true;
}
void OnCollisionExit2D(Collision2D col)
{
if (col.gameObject.name == "ground")
isGrounded = false;
}
void OnFirstTouchBegan(){
switch (buttonType)
{
case type.JumpButton:
if (playerObject.GetComponent<PlayerManager> ().onGround)
{
if (myTouchDT < .7f) {
playerRigidbody.AddForce (Vector2.up * jumpHeight, ForceMode2D.Impulse); // this make the object jump // esto checa si esta en el suelo o no pa ver si brinca o no
Debug.Log ("small");
} else if (myTouchDT >= .7f)
{
playerRigidbody.AddForce (Vector2.up * jumpHeight, ForceMode2D.Impulse); // this make the object jump // esto checa si esta en el suelo o no pa ver si brinca o no
Debug.Log ("keep jumping");
}
myTouchDT = 0f;
}
break;
}
}
Comment
How are you going to tell the different between holding for a big jump and lots of small jumps?
You can't can you, the best you can do is start recording a new hold the second you land.
Your answer
Follow this Question
Related Questions
Hold touch button Unity Javascript 1 Answer
How to change get keydown into Multiple touch in gameObject 0 Answers
Unity UI - Button Slow On Some Devices? 0 Answers
How to make an object keep move when pressing a button? 0 Answers
UI Button Double jump 0 Answers