开发过程中遇到了如何改变Cinemachine追踪对象的问题,我找遍中文论坛都没找到办法,最后还是在英文社区找到的,我稍作了一下整理
找到解决办法如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;//必须引入额外的命名空间
public class Cinema : MonoBehaviour
{
[Header("Self Component")]
public Transform Box;
public Transform Ball;//要追踪的两个对象
public CinemachineVirtualCamera camera;//声明一个camera
// Start is called before the first frame update
void Start()
{
var camera = GetComponent<CinemachineVirtualCamera>();//这里是个隐式类型,编译器会自动转译,这一步是必须的
}
// Update is called once per frame
void Update()
{
if (Global.chosen == 1)//
{
camera.Follow = Box;//改变Transform就好了
}
else
{
camera.Follow = Ball;
}
}
}
感谢Unity英文论坛