- Home /
Setting target for Camera2DFollow from script at runtime
I have a level manager that is persistent across scenes, that has a public method I can call from a UI button to change to the main menu scene, or to the game scene.
The game scene contains only a camera with a Camera2DFollow component from the standard assets. When the function that generates the level is called, it loads the game scene, uses GameObject.FindObjectOfType<Camera2DFollow>() to find the camera and then sets it's target transform to that of the newly spawned player.
My issue is that the level manager doesn't seem to find the camera. When I put a Debug.Log just after the line that finds the camera, if tells me the camera doesn't exist, even though it is constantly spitting out errors saying that it's target is null.
What is going wrong here?
Answer by MT369MT · Sep 13, 2017 at 05:21 AM
Hi Try with: GameObject.Find("The name of your camera");
Your answer
Follow this Question
Related Questions
Cinemachine Confiner 2D shift my camera view 0 Answers
Cinemachine 2D - How to reset lookahead 1 Answer
Camera following Rigidbody jitter every few seconds with background 0 Answers
How to make the Standard Asset Robot (2D) crouch? 1 Answer
2D Cinemachine with Lookahead time respawn problem 4 Answers