Not Sure Why My C# Camera Switch Script Won't Work
Hey, I'm extremely new to unity, c#, and just coding in general. I'm making a little game and want to make my camera switch when my player object is destroyed (my main camera is attached to my player and is also destroyed, so that's why). Since I'm new, I try to code by myself and follow tutorials instead of just copy code. I understand that means I'll make a lot of errors. Here is one I just can't find my way around.
public class NewBehaviourScript : MonoBehaviour { // Update is called once per frame void Update() { MakeMain(GameObject.Find("Camera1")); } void MakeMain(GameObject secondary) { if(Camera.main == null) { secondary.gameObject.SetActive(true); } } }
When my player object is destroyed the Camera.main will come back null. I have my Camera1 cam set unactive. I'm not sure why it isn't being set to active after my main camera is destroyed and being displayed on the screen. It just says, "Display 1 No cameras rendering". I have the script set to Camera1 currently, which I think that's how it should be. This might be a little confusing (I'm confused), but a little help would be awesomely appreciated. Again, you might think I'm dumb, but I'm just really new to this. If you need any more clarification on my question, I'll reply ASAP. Thanks so much!