1091229 讓物件跟隨目標
by 黃國哲 2020-12-29 18:48:39, 回應(0), 人氣(959)
www.itread01.com/content/1549613550.html
使用以下代碼
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class followCam : MonoBehaviour {
public Transform targetTr;
public float dist = 5f;
public float height = 5.0f;
public float dampTrace = 10.0f;
public Transform tr;
// Use this for initialization
void Start () {
tr = GetComponent<Transform> ();
}
// Update is called once per frame
void LateUpdate () {
tr.position = Vector3.Lerp (tr.position, targetTr.position - (targetTr.forward * dist) + (Vector3.up * height), Time.deltaTime * dampTrace);
tr.LookAt (targetTr.position);
}
}
回應