//SceneScript
using?UnityEngine;
using?System.Collections;
public?class?SceneScript?:?MonoBehaviour?{
public?GameObject?Player;
public?GameObject?camera;
//?Use?this?for?initialization
void?Start?()?{
camera?=?this.gameObject;
}
//?Update?is?called?once?per?frame
void?Update?()?{
}
void?LateUpdate()
{
if?(Player?!=?null)?{
camera.transform.LookAt(Player.transform.position);
}
}
}
//test
using?UnityEngine;
using?System.Collections;
public?class?test?:?MonoBehaviour?{
public?int?walkspeed;
//?Use?this?for?initialization
void?Start?()?{
GameObject.Find("Main?Camera").GetComponent<SceneScript>?().Player?=?this.gameObject;
}
//?Update?is?called?once?per?frame
void?Update?()?{
forward?();
}
void?forward?()
{
transform.position?=?transform.position?+?walkspeed?*?transform.forward*Time.deltaTime;
return;
throw?new?System.NotImplementedException?();
}
}
2016-08-21
Camrea是GameObject上的一個(gè)組件,就是Component,不是一個(gè)GameObject
2015-12-22
是的。Camera是GameObject.Camera