- Home /
Why cant any operations be performed in camera when loaded from the previous scene?
I have a start scene which has a start button. The start scene has a Camera adaptor gameobject. Camera adaptor gets main camera and performs some operations on every scene. When I click on start and the next scene is loaded, the camera adapter object is available in next scene but the camera and camera is also loaded. But I cannot perform any operations on camera like changing its position, etc. here is my code and configuration: alt text
public class CameraAdaptor2D : MonoBehaviour
{
float displayWidth;
float displayHeight;
[SerializeField] Camera cam;
void OnEnable()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
cam = Camera.main;
}
// called when the game is terminated
void OnDisable()
{
Debug.Log("OnDisable");
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void Awake()
{
DontDestroyOnLoad(this);
}
void Start()
{
displayWidth = Screen.width;
displayHeight = Screen.height;
PositionCamera();
}
void PositionCamera()
{
Vector3 vector = new Vector3(0.0f,0.0f,0.0f);
cam.transform.position = vector;
}
In the above code, the camera stays in its position. It does not move. even when I try to debug and add a breakpoint in PositionCamera(), it does not hit that breakpoint. What amI doing wrong here? How can I correct it?
Your answer
Follow this Question
Related Questions
Problems changing camera position 1 Answer
How to make the tower shoot at the one who is closer to the finish line? 0 Answers
I want to lerp between different changing values 1 Answer
Having trouble with Position X location on objects 0 Answers
unity networking not working,Unity networking not working 0 Answers