How to make the camera of the second scene follow the object from the first scene?,How do I make my camera follow my object from another 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 second scene hoping it will work but it didn't. Is there a workaround about this? Thank you!
,So, let's say I have this Player-tagged object Black Wizard. I have a code that the camera follows him in the original scene, but whenever I teleport him to a different scene, the camera doesn't follow him. Here's the code 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 also used that code to the new scene hoping the camera would follow the player even if I referenced the Black Wizard in the same script in the second scene. How do I fix this?
Your answer
