1.获取相机射线
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
//GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position = ray.GetPoint(10.0f);
transform.LookAt(ray.GetPoint(10.0f));
2.AddForce和velocity有什么区别?
AddForce是施加一个力,这样运动是靠力产生的加速度,然后就加速前进。
直接使用Velocity,速度很平稳,移动为恒定值,相当于直接给设定了一个恒定的速度。
3.检测哪个按键被按下
public void DetectPressedKeyOrButton()
{
foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
{
if (Input.GetKeyDown(kcode))
{
Debug.Log("KeyCode down: " + kcode);
}
}
}
4.在控制面板上查看脚本的私有变量
选中你的脚本文件,然后右键点击Inspector,默认是Normal改成Debug