using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SnakeHead_text : MonoBehaviour
{
public float Velocity = 0.35f;
public int steep;
private int x;
private int y;
private Vector3 headPos;
private void Start()
{
InvokeRepeating("Move", 0, Velocity);//重复调用,按照“Velocity”频率,在0秒后立即调用;
x = steep;y = 0;//在开始时就向右移动
}
private void Update()
{
if (Input .GetKey (KeyCode.W ))
{
x = 0;y = steep;
}
if (Input.GetKey(KeyCode.S ))
{
x = 0; y = -steep;
}
if (Input.GetKey(KeyCode.A ))
{
x = -steep ; y = 0;
}
if (Input.GetKey(KeyCode.D ))
{
x = steep ; y = 0;
}
}
void Move()
{
headPos = gameObject.transform.localPosition;
gameObject.transform.localPosition = new Vector3(headPos.x + x, headPos.y + y, headPos.z);
}
}