Hi everyone
I’ll start explaining how my game goes: my player is always running. What I want is that when he stand on an tagged object, the float named moveSpeed be equal to 0, in other words, he stop running
public class GlenController : MonoBehaviour {
public float moveSpeed;
public float jumpForce;
private Rigidbody2D rb2d;
public bool grounded;
public LayerMask whatIsGround;
private Collider2D myCollider;
private Animator anim;
// Use this for initialization
void Start () {
rb2d = GetComponent<Rigidbody2D> ();
myCollider = GetComponent<Collider2D> ();
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
grounded = Physics2D.IsTouchingLayers (myCollider, whatIsGround);
rb2d.velocity = new Vector2 (moveSpeed, rb2d.velocity.y);
if (CrossPlatformInputManager.GetButtonDown ("Jump")) {
if (grounded) {
rb2d.velocity = new Vector2 (rb2d.velocity.x, jumpForce);
}
}
if (CrossPlatformInputManager.GetButtonDown ("Slide")) {
anim.SetBool ("slide", true);
}
else if (!CrossPlatformInputManager.GetButtonDown("Slide")){
anim.SetBool ("slide", false);
}
anim.SetFloat ("Speed", rb2d.velocity.x);
anim.SetBool ("Grounded", grounded);
}
}