I have 2 scenes in my project, MainMenu and Game.
MainMenu scene contains 2 buttons, 'Hide Black' and 'Hide White'. Game scene contains 2 panels, 'Black' and 'White'. When the user clicks any of button from main menu, I wanna hide the corresponding panel in Game scene and also load the scene. This is the script for the same.
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour {
public void HideBlack() {
SceneManager.LoadScene(1);
GameObject black = GameObject.Find("Black");
black.SetActive(false);
}
public void HideWhite() {
SceneManager.LoadScene(1);
GameObject white = GameObject.Find("White");
white.SetActive(false);
}
}
But it turns out that GameObject.Find can't find the panels in my Game scene. I looked my forums for help but I find them confusing. What's going on here?
EDIT - This is not from my actual project. I created these scenes just to explain the problem better. I must use 2 scenes in my actual project as I have 3D objects in Game scenes.