- Home /
unity 2D with delay run and jump
I'm trying run and jump my player, but my code stay with delay... I stoped run and my player keep run or jump about 1 second more. I'm using the last version Unity and my code is 2D.
Look at my code below:
public class Player : MonoBehaviour {
public float velociadade;public Transform player ;public Transform Ground;public Animator animator;public bool isGround;public float force = 200f;public float jumpTime = 0.5f;public float jumpDelay = 0.5f;public bool jumped ;void Start (){animator = player.GetComponent ();}void Update (){Movimentar ();}void Movimentar (){isGround = Physics2D.Linecast(this.transform.position,``Ground.position,1<
animator.SetFloat ("run", Mathf.Abs (Input.GetAxis("Horizontal")));
if (Input.GetAxisRaw ("Horizontal") > 0) {transform.Translate (Vector2.right * velociadade *Time.deltaTime); transform.eulerAngles = new Vector2 (0, 0); }
if (Input.GetAxisRaw ("Horizontal") < 0) {transform.Translate (Vector2.right * velociadade *Time.deltaTime); transform.eulerAngles = new Vector2 (0, 180); }
bool up = Input.GetKeyUp(KeyCode.Space);if (up && isGround && !jumped){GetComponent().AddForce(transform.up
force); jumpTime = jumpDelay; animator.SetTrigger("jump");
jumped = true;}jumpTime -= Time.deltaTime;if (jumpTime <= 0 && isGround && jumped) {animator.SetTrigger("ground");jumped = false;}}
unity2.png
(78.2 kB)
unity3.png
(97.2 kB)
Comment
Your answer
