Can't animate using accelerometer

Hello, everyone. This is my first post so I hope I’m in not posting it on the wrong place.

I’m trying to animate my Player while I’m using my Android Phone accelerometer but it doesnt switch animations. Even when it’s still, the Idle animation doesnt play. What am I doing wrong?

Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{
    private Rigidbody2D rb;
    private float xMv;
    private float yMv;
    private Vector2 direction;
    private int scrWdt;
    private int scrHgt;
    private Vector2 screenSize;
    private Animator anim;

    [SerializeField] int mvntSpeed;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        anim = GetComponent<Animator>();
        scrHgt = Screen.height;
        scrWdt = Screen.width;
        screenSize = new Vector2(scrWdt, scrHgt);


    }

  
    void Update()
    {
        InputAccess();
       

    }

    void FixedUpdate()
    {
        rb.velocity = new Vector2(xMv, yMv) * mvntSpeed;
    }

    public void InputAccess()
    {
        xMv = Input.acceleration.x;
        yMv = Input.acceleration.y;

        //direction = new Vector2(xMv, yMv) * mvntSpeed;
        //rb.AddForce(direction);
       
        if(xMv > 0)
        {
            Debug.Log("Right");
            anim.SetBool("Direita", true);
           
        }
        else if(xMv < 0)
        {
            Debug.Log("Left");
            anim.SetBool("Left", true);

        }
         else if(yMv < 0)
        {
            Debug.Log("Down");
            anim.SetBool("Down", true);

        }
         else if(yMv > 0)
        {
            Debug.Log("Up");
           
        }
        else
        {
            Debug.Log("Idle");
        }  
    }
}


5344158--539415--1.gif

Please show your Debug.Log output. Where do you play the animation?

  • if UP,DOWN,RIGHT,LEFT Debug Log Proper Show then conditions fine,

  • but Check Animator Boolean variables inside animator tab

  • and make “any state” state to direction to idle,left,right,up,down whatever And Don’t Forget assign proper Boolean variables,if required else to set false all the Boolean variables your accelerators control conditions.

“any state” Flow Show in diagram : it is proper way to Animate Player

Please show your Debug.Log output, and the code that calls them all.