hi there, I recently started working on my own game and what I’d like to do is exactly what the title suggests. Right now I have my game setup with a base scene which never unloads where I keep my player and my camera. The problem with this is that I can’t set confines for the camera depending on which room/scene the player is in, so I’d like to use a different camera for each scene. But I can’t set these cameras to follow the player which I keep in my base scene.
Is there a solution for this? I’ve done a lot of research but I couldn’t really find anything, it seems cross-scene references is one of Unity’s weaker points, that said I know that something like this should be possible as this is what Hollow Knight(game which was built in unity) does.
Hi, you will need to set refference for follow traget when new camera loads. So I suggest you that you put some custom script on your camera and when camera first loads you assign your player to follow refference vc.m_Follow = GameObject.FindGameObjectWithTag( "Player" ).transform;.
2 Likes
Thank you that worked!
Here’s the exact code I used in case anyone has the same problem
public class CameraScript : MonoBehaviour
{
private CinemachineVirtualCamera vcam;
void Start()
{
var vcam = GetComponent<CinemachineVirtualCamera>();
vcam.Follow = GameObject.FindGameObjectWithTag("Player").transform;
}
}
1 Like