バーチャルカメラからCinemachineTrackedDollyコンポーネントを取得し、それのm_PathPositionを操作すればよさそうです。
C#
1using Cinemachine;
2using UnityEngine;
3
4public class DollyDriver : MonoBehaviour
5{
6 [SerializeField] private CinemachineVirtualCamera virtualCamera;
7 [SerializeField] private float cycleTime = 10.0f;
8
9 private CinemachineTrackedDolly dolly;
10 private float pathPositionMax;
11 private float pathPositionMin;
12
13 private void Start()
14 {
15 // バーチャルカメラがセットされていなければ中止
16 if (this.virtualCamera == null)
17 {
18 this.enabled = false;
19 return;
20 }
21
22 // ドリーコンポーネントを取得できなければ中止
23 this.dolly = this.virtualCamera.GetCinemachineComponent<CinemachineTrackedDolly>();
24 if (this.dolly == null)
25 {
26 this.enabled = false;
27 return;
28 }
29
30 // Positionの単位をトラック上のウェイポイント番号基準にするよう設定
31 this.dolly.m_PositionUnits = CinemachinePathBase.PositionUnits.PathUnits;
32
33 // ウェイポイントの最大番号・最小番号を取得
34 this.pathPositionMax = this.dolly.m_Path.MaxPos;
35 this.pathPositionMin = this.dolly.m_Path.MinPos;
36 }
37
38 private void Update()
39 {
40 // cycleTime秒かけてトラック上を往復させる
41 var t = 0.5f - (0.5f * Mathf.Cos((Time.time * 2.0f * Mathf.PI) / this.cycleTime));
42 this.dolly.m_PathPosition = Mathf.Lerp(this.pathPositionMin, this.pathPositionMax, t);
43 }
44}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/24 00:47
2019/11/14 07:02