,DirectionalLight的效果由Rotation决定而不是Position。
创建了新的object一定要先reset。
FrameSelected用于将摄像机对准某个object。
想要object有力的效果或是匀速移动,或识别撞击(Collider/Trigger),需对其添加rigidbody组件,同时编写的相关程序脚本也在相应object中添加。
左右运动在X轴,前后运动在Z轴。
使小球运动的代码:
public class playercontroller : MonoBehaviour {
public float speed;/**这个选项可以在player的Inspector中输入*/
void FixedUpdate()/**与物理相关的代码卸载这个方法里*/
{
float moveHorizontal = Input.GetAxis ("Horizontal");/**水平方向的移动输入,左右*/
float moveVertical = Input.GetAxis ("Vertical");/**垂直方向上的移动输入,前后*/
Vector3 movement = new Vector3 (moveHorizontal, 0.0f,moveVertical);/**movement中存放了各方向上移动的数据*/
GetComponent<Rigidbody>().AddForce(movement*speed*Time.deltaTime);/*通过movement做参数,决定了施加力的方向和大小*/
}
}
建立摄像机与小球间联系的代码:
public class CameraContrlloer : MonoBehaviour {
public GameObject player;
priv