Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

reference to gameobject in different scene unity

//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
Comment

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);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: ssml 
Csharp :: how to configure visual studio for unity 
Csharp :: strong email validation regex c# 
Csharp :: matrix transpose 
Csharp :: datatable select c# 
Csharp :: loop in c# 
Csharp :: how to call a method from a class c# 
Csharp :: raycasting unity 
Csharp :: convert stream to base64 string c# 
Csharp :: send mail c# 
Csharp :: c# delete object 
Csharp :: get camera position unity 
Csharp :: jobject alternative in system.text.json 
Csharp :: for loop c# to print times tables 
Csharp :: dadar pincode 
Csharp :: Uninstall-SPSolution: This solution contains resources scoped for a Web application and must be retracted from one or more Web applications. 
Csharp :: c# Prefix Sum of Matrix (Or 2D Array) 
Csharp :: c# fold sum array 
Csharp :: custom attribute for auth permission check .net 
Csharp :: if exist request c# 
Csharp :: set ByteArrayContent content type json 
Csharp :: [Package Manager Window] Error while fetching labels: User is not logged in or user status invalid. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) 
Csharp :: asp:button onclick not respond 
Csharp :: enumerate dictionary c# 
Csharp :: C# assign integer 
Csharp :: IEqualityComparer gethashcode strings c# 
Csharp :: C# check control type 
Csharp :: SerializedObjectNotCreatableException: Object at index 0 is null 
Csharp :: c# Jarray tryparse 
Csharp :: unity diference protected and virtual 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =