using UnityEngine;
using System.Collections;
public class player : MonoBehaviour {
public float velocidade;
public Transform playe;
private Animator animator;
public bool isGrounded;
public float force;
public float JumpTime = 0.4f;
public float JumpDelay = 0.4f;
public bool Jumped = false;
public Transform ground;
// Use this for initialization
void Start () {
animator = playe.GetComponent <Animator> ();
}
// Update is called once per frame
void Update () {
Movimentacao();
}
void Movimentacao() {
isGrounded = Physics2D.Linecast(this.transform.position, ground.position, 1 << LayerMask.NameToLayer("plataforma"));
animator.SetFloat ("correndo", Mathf.Abs (Input.GetAxis ("Horizontal")));
if (Input.GetAxisRaw("Horizontal") > 0 ) {
transform.Translate (Vector2.right * velocidade * Time.deltaTime);
transform.eulerAngles = new Vector2(0, 0);
}
if (Input.GetAxisRaw("Horizontal") < 0 ){
transform.Translate (Vector2.right * velocidade * Time.deltaTime);
transform.eulerAngles = new Vector2(0,180);
}
if (Input.GetButtonDown("Jump")&& isGrounded && !Jumped ) {
rigidbody2D.AddForce(transform.up * force);
JumpTime = JumpDelay;
animator.SetTrigger ("jump");
Jumped=true;
}
JumpTime -= Time.deltaTime;
if (JumpTime <= 0 && isGrounded && Jumped) {
animator.SetTrigger("ground");
Jumped=false;
}
}
}