using UnityEngine;
public class LookAtTarget : MonoBehaviour {
public Transform target;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//当目标对象运动时,始终面向物体
//transform.LookAt(target);
//当目标对象运动时,始终转向物体
//但是尽在Y轴上旋转,而不会上下旋转
//不造成物体倾斜
transform.LookAt(new Vector3(target.position.x, transform.position.y, target.position.z));
}
}