using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public float moveSpeed = 5f; // 移动速度
public float rotateSpeed = 180f; // 旋转速度
// Start is called before the first frame update
void Start()
{
tx= this.gameObject.GetComponent
animator=this.gameObject.GetComponent
}
public Transform tx;
private Animator animator;
// Update is called once per frame
bool bool_run=false;
void Update()
{
// 按下W键向前移动
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
//if(Input.GetAxis("bool_run")==false)
//if(!bool_run)
{
bool_run=true;
animator.SetBool("bool_run",true);
//animator.Play("run");
}
}
// animator.SetBool("bool_run",false);
// 按下W键向前移动
if (Input.GetKey(KeyCode.Space))
{
//animator.Play("jum");
}
// 按下S键向后移动
if (Input.GetKey(KeyCode.S))
{
transform.Translate(Vector3.back * moveSpeed * Time.deltaTime);
}
// 按下A键向左移动
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);
Vector3 angle = tx.localEulerAngles;
angle.y -=0.5f;
tx.localEulerAngles = angle;
}
// 按下D键向右移动
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);
Vector3 angle = tx.localEulerAngles;
angle.y +=0.5f;
tx.localEulerAngles = angle;
}
// 按下Q键向下移动
if (Input.GetKey(KeyCode.Q))
{
transform.Translate(Vector3.down * moveSpeed * Time.deltaTime);
}
// 按下E键向上移动
if (Input.GetKey(KeyCode.E))
{
transform.Translate(Vector3.up * moveSpeed * Time.deltaTime);
}
// 按下左箭头键向左旋转
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.Rotate(Vector3.up, -rotateSpeed * Time.deltaTime);
}
// 按下右箭头键向右旋转
if (Input.GetKey(KeyCode.RightArrow))
{
transform.Rotate(Vector3.up, rotateSpeed * Time.deltaTime);
}
}
}