- Home /
How to make the second scene camera follow the object from the first scene?
I have a Player-tagged object, let's say "Black Wizard." In the first scene, the camera follows him wherever he goes, but when I teleport him to the second scene, the camera would stay still and not follow him.
Here's the code I attached to the Main Camera for both scenes:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public GameObject player;
private Vector3 offset;
// Use this for initialization
void Start () {
GameObject.FindWithTag("Player");
offset = transform.position - player.transform.position;
}
// Update is called once per frame
void LateUpdate () {
transform.position = player.transform.position + offset;
}
}
I even referenced the Black Wizard Prefab to the same script of the second scene hoping it will work but it didn't. Is there a workaround about this? Thank you!
Comment
Answer by knobblez · Dec 02, 2018 at 05:56 PM
Is the same camera being carried over? Make sure the script is on the camera in scene2.
I did that but it didn't work. I even used DontDestroyonLoad() function.
Your answer
![](https://koobas.hobune.stream/wayback/20220612183134im_/https://answers.unity.com/themes/thub/images/avi.jpg)