using UnityEngine;
using UnityEngine.UI;
public class move : MonoBehaviour {
private float speed = 10f;//初始速度
public bool isPPP = false;//这是一个检测的状态
public Toggle to;//UI
public Text toText;//文本
void Update () {
float v = Input.GetAxis("Vertical");
ChangeSpeed();//调用状态检测的方法
if (isPPP == false)//判断这个状态下是初始速度
{
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S))
{
float ratation = v * speed * Time.deltaTime;
transform.Translate(ratation, 0, ratation);
}
}
if(isPPP == true)//这个状态下是新赋予的速度
{
float speed = 50f;
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S))
{
float ratation = v * speed * Time.deltaTime;
transform.Translate(ratation, 0, ratation);
}
}
}
//检测状态以及改变状态的方法
public void ChangeSpeed()
{
if (isPPP == false)
{
if (Input.GetKey(KeyCode.LeftShift))
{
to.GetComponent<Toggle>().isOn = true;
toText.text = "疾風步";
toText.GetComponent<Text>().color = Color.red;
isPPP = true;
}
}
else if (isPPP == true)
{
if (Input.GetKeyUp(KeyCode.LeftShift))
{
to.GetComponent<Toggle>().isOn = false;
toText.text = "走路";
toText.GetComponent<Text>().color = Color.green;
isPPP = false;
}
}
}
}
物体移动时按下Shift键加快速度
猜你喜欢
转载自blog.csdn.net/qq_38962400/article/details/79273220
今日推荐
周排行