代碼很簡單,這里就不多廢話了,直接奉上代碼
using UnityEngine;using System.Collections; public class FllowTarget : MonoBehaviour {   public Transform character;  //攝像機(jī)要跟隨的人物  public float smoothTime = 0.01f; //攝像機(jī)平滑移動(dòng)的時(shí)間  private Vector3 cameraVelocity = Vector3.zero;  private Camera mainCamera; //主攝像機(jī)(有時(shí)候會(huì)在工程中有多個(gè)攝像機(jī),但是只能有一個(gè)主攝像機(jī)吧)    void Awake ()   {    mainCamera = Camera.main;  }   void Update()  {    transform.position = Vector3.SmoothDamp(transform.position, character.position + new Vector3(0, 0, -5), ref cameraVelocity, smoothTime);  }  }以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡,能夠?qū)Υ蠹覍W(xué)習(xí)unity有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選