Guys please help me with this SceneManager in Unity 5
Hello Guys I have this code
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; namespace BombedOut { public class GameManager_GoToMenuScene : MonoBehaviour {
private GameManager_Master gameManagerMaster;
void OnEnable()
{
SetIniialReferences();
gameManagerMaster.GoToMenuSceneEvent += GoToMenuScene;
}
void OnDisable()
{
gameManagerMaster.GoToMenuSceneEvent -= GoToMenuScene;
}
void SetIniialReferences()
{
gameManagerMaster = GetComponent<GameManager_Master>();
}
void GoToMenuScene()
{
SceneManager.LoadScene(0);
}
}
}
this is to access the main menu when i click the menu button and the bug is i wont jump into that scene please help
I've had some issues getting unity to play nice with custom events and delegates. It looks like that is what you are trying to do here, so could you provide the definition code for the delegate and event?
using UnityEngine; using System.Collections;
namespace BombedOut {
public class Game$$anonymous$$anager_$$anonymous$$aster : $$anonymous$$onoBehaviour
{
public delegate void Game$$anonymous$$anagerEventHandler();
public event Game$$anonymous$$anagerEventHandler $$anonymous$$enuToggleEvent;
public event Game$$anonymous$$anagerEventHandler InventoryUIToggleEvent;
public event Game$$anonymous$$anagerEventHandler RestartLevelEvent;
public event Game$$anonymous$$anagerEventHandler GoTo$$anonymous$$enuSceneEvent;
public event Game$$anonymous$$anagerEventHandler GameOverEvent;
public bool isGameOver;
public bool isInventoryUIOn;
public bool is$$anonymous$$enuOn;
public void CallEvent$$anonymous$$enuToggle()
{
if ($$anonymous$$enuToggleEvent != null)
{
$$anonymous$$enuToggleEvent();
}
}
public void CallEventInventoryUIToggle()
{
if (InventoryUIToggleEvent != null)
{
InventoryUIToggleEvent();
}
}
public void CallEventRestartLevel()
{
if (RestartLevelEvent != null)
{
RestartLevelEvent();
}
}
public void CallEventGoTo$$anonymous$$enuScene()
{
if (GoTo$$anonymous$$enuSceneEvent != null)
{
InventoryUIToggleEvent();
}
}
public void CallEventGameOver()
{
if (GameOverEvent != null)
{
isGameOver = true;
GameOverEvent();
}
}
}
}
I'd advise moving the delegate outside of the class.
Answer by Magius96 · Feb 27, 2016 at 05:47 AM
Now that I take a second look, you are making references to the
private GameManager_Master gameManagerMaster;
But I don't see a start method, or any point, where you are assigning anything to that.
Assuming you have a game object in your scene named "GameManagerMaster" and it has the component script GameManager_Master attached to it, then in your script above you need to add
void Start()
{
var obj = GameObject.Find("GameManagerMaster");
gameManagerMaster = obj.GetComponent<GameManager_Master>();
}
sir I am following a tutorial particularly this: https://www.youtube.com/watch?v=FwAW$$anonymous$$Q7Fi6k&list=PLwyZdDTyvucwjwqucleVQB7U12H2JPvg5∈dex=39
can you take a second look of this sir because I am a newbie in unity
Your answer
Follow this Question
Related Questions
C# scripts not showing up in scene... please help! 0 Answers
LoadScene not working 0 Answers
I'm facing issue in creating a MainMenu of a 2D Game in Unity 5.5 0 Answers
Switching back and fourth between scenes help (script) 0 Answers
How to change scenes when camera enters a collider. (answerer will be rewarded) 2 Answers