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

posted on 2016-11-27 13:34  春天里的麦子  阅读(266)  评论(0)    收藏  举报