Untitled
public class pacman : MonoBehaviour { // Start is called before the first frame update private Rigidbody2D rb; public int speed = 1; // Velocidad de Pac-Man private Vector2 direction; // Dirección actual del movimiento void Start() { rb = GetComponent<Rigidbody2D>(); } // Update is called once per frame void Update() { if (Input.GetKey(KeyCode.UpArrow)) direction = Vector2.up; // Arriba else if (Input.GetKey(KeyCode.DownArrow)) direction = Vector2.down; // Abajo else if (Input.GetKey(KeyCode.LeftArrow)) direction = Vector2.left; // Izquierda else if (Input.GetKey(KeyCode.RightArrow)) direction = Vector2.right; // Derecha rb.velocity = direction * speed; } }
Leave a Comment