Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by neemineem · Feb 27, 2016 at 04:23 AM · scripting problemscene-switching

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

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Magius96 · Feb 27, 2016 at 05:42 AM 0
Share

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?

avatar image neemineem Magius96 · Feb 28, 2016 at 03:09 AM 0
Share

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();

         }

     }


 }



}

avatar image Magius96 neemineem · Mar 02, 2016 at 06:39 AM 0
Share

I'd advise moving the delegate outside of the class.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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>();
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image neemineem · Feb 27, 2016 at 06:00 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

51 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges