//the truth is, you shouldn't. its better to just add delegates to
//SceneManager.sceneLoaded and SceneManager.sceneUnloaded
//if you really need to,
FindObjectOfType<Canvas>();
//searches across all additively loaded scenes
Posted by: Guest
on May-29-2020
0
reference to gameobject in different scene unity
public Canvas menu;
// Start is called before the first frame update
void Start()
{
//not in OnEnabled since we want these methods to be called on startup
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
}
void OnDestroy()
{
//not in OnDisabled since we want these methods to be removed only when destroyed, not switched out of
SceneManager.sceneLoaded -= OnSceneLoaded;
SceneManager.sceneUnloaded -= OnSceneUnloaded;
}
//when a scene is loaded, make this canvas invisible
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
menu.gameObject.SetActive(false);
}
//when a scene is unloaded, make this canvas visible again
void OnSceneUnloaded(Scene current)
{
menu.gameObject.SetActive(true);
}
Posted by: Guest
on May-29-2020
Code answers related to "reference to gameobject in different scene unity"
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems
resetting your password contact us
Check Your Email and Click on the link sent to your email