Search Unity

Animation.setbool does not contain this definition

Discussion in 'Animation' started by francorferreyra27, Jun 10, 2019.

  1. francorferreyra27

    francorferreyra27

    Joined:
    Jun 10, 2019
    Posts:
    1
    The problem is when I want to put animation.setbool / setfloat tells me that there is no definition for the





    This is the code
    public class Movimiento : MonoBehaviour
    {
    public float maxSpeed = 5f;
    public float Speed = 20f;
    public float jumpForce = 3f;
    public float Radio = 0.5f;
    public Transform pie;
    public LayerMask Suelo;
    private Animation animacion;


    private Vector2 jump;
    public bool isGrounded = true;
    private bool corriendo = false;

    private Rigidbody2D rb2d;


    // Start is called before the first frame update
    void Start()
    {
    rb2d = GetComponent<Rigidbody2D>();
    jump = new Vector2(0, 10);
    animacion = GetComponent<Animation>();


    }

    // Update is called once per frame
    void Update()
    {

    }

    void FixedUpdate()
    {
    isGrounded = Physics2D.OverlapCircle(pie.position, Radio, Suelo);
    if (Input.GetKey(KeyCode.D))
    {
    rb2d.AddForce(Vector2.right * Speed);
    animacion.SetBool("Caminar", true);

    }
    if (Input.GetKey(KeyCode.A))
    {
    rb2d.AddForce(Vector2.left * Speed);
    }
    if(Input.GetKeyDown(KeyCode.Space) && isGrounded)
    {
    rb2d.AddForce(jump * jumpForce, ForceMode2D.Impulse);
    isGrounded = false;
    }

    }
    }
     
  2. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
  3. Ajkaz

    Ajkaz

    Joined:
    Apr 22, 2020
    Posts:
    1
    I know this thread is a couple years old, but this problem occurred for me, too, and I wanted to share my findings in case this is useful to anyone in the future.

    The source of the problem turned out to be this: When trying to add an Animator to a gameObject, I had accidentally created a new script entitled "Animator." This script, of course, contained no definition for the method SetFloat(), so Unity threw errors (in fact, it insisted on launching in Safe Mode). Locating and deleting this script (which was in the root Asset folder) fixed the problem.