Помогите персонаж никак не двигается, нажимаю на стрелки а он ни в какую, даже анимацию не показывает
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovePacmen : MonoBehaviour
{
public float speed = 0.4f;
Vector2 pos = Vector2.zero;
void Start()
{
pos = transform.position;
}
void FixedUpdate()
{
Vector2 p = Vector2.MoveTowards(transform.position, pos, speed);
GetComponent<Rigidbody2D>().MovePosition(p);
if ((Vector2)transform.position == pos)
{
if (Input.GetKey(KeyCode.UpArrow) && valid(Vector2.up))
pos = (Vector2)transform.position + Vector2.up;
if (Input.GetKey(KeyCode.RightArrow) && valid(Vector2.right))
pos = (Vector2)transform.position + Vector2.right;
if (Input.GetKey(KeyCode.DownArrow) && valid(-Vector2.up))
pos = (Vector2)transform.position - Vector2.up;
if (Input.GetKey(KeyCode.LeftArrow) && valid(-Vector2.right))
pos = (Vector2)transform.position - Vector2.right;
}
Vector2 dir = pos - (Vector2)transform.position;
GetComponent<Animator>().SetFloat("DirX", dir.x);
GetComponent<Animator>().SetFloat("DirY", dir.y);
}
bool valid(Vector2 dir)
{
Vector2 pos = transform.position;
RaycastHit2D hit = Physics2D.Linecast(pos + dir, pos);
return (hit.collider == GetComponent<Collider2D>());
}
}