unity3D让Camera跟随人物移动

private Tranform player;//玩家
private Vector3 Offset;
private float speed=3;
void Start()
{
     player=GameObject.FindGameObjectWithTag("player").tranform;
     Offset=tranform.position-player.position;//獲取人物到相機的距離
}
void LateUpdate () {
        Vector3 traget = Player.position+Player.TransformDirection(offset);//將offset轉換成區域坐標
        transform.position = Vector3.Lerp(transform.position, traget, Time.deltaTime * speed);
        transform.LookAt(Player.position);

	}

你可能感兴趣的:(unity3D让Camera跟随人物移动)