看向目标物体transform.LookAt()
public GameObject go;
void Start () {}
void Update () {
gameObject.transform.LookAt(go.transform.position);
}
跟随鼠标移动
void Update () {
//获取射线
Ray ray = Camera.main.ScreenPointToRay(Input .mousePosition);
RaycastHit hit;
//检测碰撞并获取碰撞信息
if (Physics .Raycast (ray ,out hit )) {
hit.point = new Vector3(hit .point .x ,transform .position .y,hit .point .z);
transform.LookAt(hit .point );
}
}