how can i add my animation into this script?
I'm doing 2D movement and its directions is up/down and left/right, I am having difficulty adding animations into it. Any suggestions? my animation movement is moveX and visa versa for Y, and i do have moving animation called moving.
public float moveSpeed = 5f;
public Transform movePoint;
private Animator animator;
// Start is called before the first frame update
void Start()
{
movePoint.parent = null;
animator = GetComponent <Animator>();
}
// Update is called once per frame
void Update()
{
transform.position = Vector3.MoveTowards(transform.position, movePoint.position, moveSpeed * Time.deltaTime);
if (Vector3.Distance(transform.position, movePoint.position) <= 0.01f)
{
if ((Input.GetKey(KeyCode.UpArrow)))
{
movePoint.position += new Vector3(0f, 0.07f, 0f);
}
else if ((Input.GetKey(KeyCode.DownArrow)))
{
movePoint.position += new Vector3(0f, -0.07f, 0f);
}
else if ((Input.GetKey(KeyCode.LeftArrow)))
{
movePoint.position += new Vector3(-0.07f, 0f, 0f);
}
else if ((Input.GetKey(KeyCode.RightArrow)))
{
movePoint.position += new Vector3(0.07f, 0f, 0f);
}
}
}
}
Comment