A. 半蹲
半蹲就是通过调低controller控件center的高度来实现——同时调节height
[也就是Center的Y坐标(控制高度)和下面的Height]
if (Input.GetButton("Duck")) //当按下ctrl的时候,实现半蹲的功能
{
controller.height = duckHeight;
controller.center = new Vector3(controller.center.x, controller.height / 2 + 0.25f, controller.center.z);
moveDirection *= duckSpeed; //速度减慢一半
B. Debug.Log
很奇怪,Debug.Log(“xxxx”);
这样输出文本的时候,你要先打开console窗口的问号标志(点一下先打开),不然运行的时候就没有输出;
或者参考其他人的方法:后面加一句 Debug.LogWarning(“无用警告”);
C. scripts的引用
创建了两个脚本,需要在其中一个脚本中引用另一个,需要添加引用,其实就是实例化:
例如在Wifget_Controller.cs中引用Widget_Status.cs中的内容:
public Widget_Status widgetStatus;
void Start () {
widgetStatus = GetComponent<Widget_Status>();
}
private void FixedUpdate