# Animator in Script

The parameters can be set in the Animator controller. Anything in "Quotes" is what you wrote down as a variable there.

```csharp
[SerializeField] private Animator anim;
```

Drag the GameObject in the scene view into the "Anim" field.

<figure><img src="/files/xvhvDznQYA3qUOnYYMHI" alt=""><figcaption></figcaption></figure>

{% code fullWidth="true" %}

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    private Vector2 movementInput;
    [SerializeField] private float MOVESPEED = 4.0f;
    private Rigidbody2D rb;

    [SerializeField] private Animator anim;


    private void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
    }


    public void OnMove(InputAction.CallbackContext ctx)
    {
        movementInput = ctx.ReadValue<Vector2>();

        if (movementInput.x == 1 || movementInput.x == -1 || movementInput.y == 1 || movementInput.y == -1)
        {
            anim.SetFloat("lastMoveX", movementInput.x);
            anim.SetFloat("lastMoveY", movementInput.y);
        }
    }

    private void FixedUpdate()
    {
        //Moving the character
        rb.velocity = movementInput * (MOVESPEED * Time.fixedDeltaTime);

        //Animator Controls, make sure the quotations match the parameter names in the Animator controller
        anim.SetFloat("moveX", rb.velocity.x);
        anim.SetFloat("moveY", rb.velocity.y);
    }
}

```

{% endcode %}

Getting the direction of the look is something I'm thinking about. One thing that doesn't throw an error is this:

```csharp
Debug.Log(anim.GetFloat("lastMoveX"));
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://roxioxx.gitbook.io/unity-cookbook/2d/animator-in-script.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
