float sprad = 3f;
Rigidbody rigidbody;
float h, v;
// Start is called before the first frame update
void Start()
{
rigidbody = GetComponent
}
// Update is called once per frame
void Update()
{
//键盘事件
if (Input.GetKeyDown(KeyCode.Space))
{
transform.position = new Vector3(transform.position.x, transform.position.y + 3, transform.position.z);
}
//移动
h = Input.GetAxis("Horizontal");
v = Input.GetAxis("Vertical");
//Vector3 pos = new Vector3(h, 0, v) * Time.deltaTime * sprad;
//transform.Translate(pos);
}
void Move()
{
//移动
if (v != 0)
{
rigidbody.MovePosition(transform.position + transform.forward * v * Time.deltaTime * sprad);
}
}
void Roate()
{
//璇转
if (h != 0)
{
rigidbody.MoveRotation(rigidbody.rotation*Quaternion.Euler(0, h*Time.deltaTime*45, 0));
}
}
void FixedUpdate()
{
Move();
Roate();
}