我试图让 Cinemachine 即使在重生后也跟随我的玩家,但它不起作用,老实说我不知道还能做什么。我不想为相机制作新代码,因为 Cinemachine 有很多好的功能。
我在想我可以重置变量而不是破坏对象,这样 Cinemachine 仍然会跟随同一个对象,但是我对编码还很陌生,所以我不知道该怎么做。
这是播放器代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class Death : MonoBehaviour
{
public static Death death;
public CinemachineVirtualCamera myCinemachine;
void Start()
{
if (death == null)
{
death = GameObject.FindGameObjectWithTag("Death").GetComponent<Death>();
}
myCinemachine = GetComponent<CinemachineVirtualCamera>();
}
public Transform playerPrefab;
public Transform respawn;
public void RespawnPlayer()
{
var spawnedPlayer = Instantiate(playerPrefab, respawn.position, respawn.rotation);
Debug.Log("TODO Add Spawn Particles");
myCinemachine.m_Follow = spawnedPlayer;
}
public static void KillPlayer (Player player)
{
Destroy(player.gameObject);
death.RespawnPlayer();
}
}
这是死亡密码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Death : MonoBehaviour
{
public static Death death;
void Start()
{
if (death == null)
{
death = GameObject.FindGameObjectWithTag("Death").GetComponent<Death>();
}
}
public Transform playerPrefab;
public Transform respawn;
public void RespawnPlayer()
{
var spawnedPlayer = Instantiate(playerPrefab, respawn.position, respawn.rotation);
Debug.Log("TODO Add Spawn Particles");
}
public static void KillPlayer (Player player)
{
Destroy(player.gameObject);
death.RespawnPlayer();
}
}