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");
}
}
}

