public class MoveSnake : MonoBehaviour {
Vector2 direction = Vector2.up;
// Use this for initialization
void Start ()
{
InvokeRepeating("Move", 0.5f, 0.5f);
}
// Update is called once per frame
void Update ()
{
//开始通过WSAD操作物体的移动
if (Input.GetKey(KeyCode.W))
{
direction = Vector2.up;
}
if (Input.GetKey(KeyCode.S))
{
direction = Vector2.down;
}
if (Input.GetKey(KeyCode.A))
{
direction = Vector2.left;
}
if (Input.GetKey(KeyCode.D))
{
direction = Vector2.right;
}
}
void Move()
{
transform.Translate(direction);
}
时间: 2024-11-06 14:05:08