unity完成攝像頭追隨。本站提示廣大學習愛好者:(unity完成攝像頭追隨)文章只能為提供參考,不一定能成為您想要的結果。以下是unity完成攝像頭追隨正文
代碼很簡略,這裡就不多空話了,直接送上代碼
using UnityEngine;
using System.Collections;
public class FllowTarget : MonoBehaviour {
public Transform character; //攝像機要追隨的人物
public float smoothTime = 0.01f; //攝像機膩滑挪動的時光
private Vector3 cameraVelocity = Vector3.zero;
private Camera mainCamera; //主攝像機(有時刻會在工程中有多個攝像機,然則只能有一個主攝像機吧)
void Awake ()
{
mainCamera = Camera.main;
}
void Update()
{
transform.position = Vector3.SmoothDamp(transform.position, character.position + new Vector3(0, 0, -5), ref cameraVelocity, smoothTime);
}
}
以上所述就是本文的全體內容了,願望年夜家可以或許愛好,可以或許對年夜家進修unity有所贊助。