Search Unity

Need help with player movement

Discussion in 'Scripting' started by Kilojotaz, Nov 26, 2014.

  1. Kilojotaz

    Kilojotaz

    Joined:
    Nov 26, 2014
    Posts:
    2
    So, for the beginning, my english sucks, so i hope you guys can understand me.
    My problem is that the jump animation just dont play, and i think its because i had no triggers, maybe you can explain me how to set the right triggers for my case.
    I have this script for the movement.
    -----
    using UnityEngine;
    using System.Collections;

    public class ControlSalto : MonoBehaviour {

    public string jump="Fire1";
    public float jumpForce=1000.0f;
    public Animator anim;
    public bool grounded=false;
    public Transform groundCheck;
    public float retrasoSalto=0.5f;
    private float tiempoSalto=0.0f;
    // Use this for initialization
    void Start () {
    anim=gameObject.GetComponent<Animator>();
    }


    // Update is called once per frame
    void Update ()
    {
    grounded=Physics2D.Linecast(transform.position , groundCheck.position);
    tiempoSalto-=Time.deltaTime;
    if(tiempoSalto<=0 && grounded){
    anim.SetTrigger("isGrounded");
    }

    if(Input.GetKeyDown(KeyCode.Space))
    {
    anim.SetTrigger("isGrounded");
    rigidbody2D.AddForce(transform.up*jumpForce);
    tiempoSalto=retrasoSalto;
    //cuerpoRigido2d.AddForce(transform.up*jumpForce);
    }
    }
    }
    --
    I think im missing the triggers, but i dont know how this works, instead of the triggers, i had this:


    I need an doublejump script too because i can jump infinite times.