Unity3d--摄像机跟随 第三人称常用方式

 1 using UnityEngine;
 2 using System.Collections;
 3 /*
 4  * 摄像机跟随 第三人称常用方式
 5 */
 6 public class CameraCS : MonoBehaviour {
 7 
 8     private Transform player;
 9     private Vector3 offsetPosition;
10     // Use this for initialization
11 
12     void Awake(){
13         player = GameObject.FindGameObjectWithTag ("Player").transform;
14     }
15 
16     void Start () {
17         //摄像机朝向player
18         transform.LookAt (player.position);
19         //获取摄像机与player的位置偏移
20         offsetPosition = transform.position - player.position;
21     }
22     
23     // Update is called once per frame
24     void Update () {
25         //摄像机跟随player与player保持相对位置偏移 
26         transform.position = offsetPosition + player.position;
27     }
28 }
posted @ 2016-06-13 11:57  yuge790615  阅读(2002)  评论(0)    收藏  举报