Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Buttons are not working with my GameManager script, after scene load.

Discussion in 'UGUI & TextMesh Pro' started by SimpleGiant, Nov 2, 2015.

  1. SimpleGiant

    SimpleGiant

    Joined:
    Dec 22, 2013
    Posts:
    47
    Hello, I am making a 2D remake of an old arcade game. In doing so, the first scene creates a GameObject called GameManager. This script is responsible for keeping track of what level the player is on, playing the in-game sound track, exiting the game, and loading between scenes. I am using the new Unity5 GUI system, rigging the button to the game object, and then calling the desired function.

    I created a prefab for the GameManager and placed one in each scene, so that i can rig the buttons up the way I like. And then the GameManager has script that will not let multiple GameManagers exist at the same time. This seems to be my downfall. The scene's GUI is rigged to GameManager(B), when GameManager(A) loads that scene GameManager(B) is deleted because GameManager(A) exists. And now the GUI rigged that was rigged to GameManager(B) is not calling GameManager(A)'s functions and is not working...

    Anyone know the best way to get around this problem is?
     
  2. DWilliams

    DWilliams

    Joined:
    Jan 12, 2015
    Posts:
    63
    Maybe separate out the button functionality into scripts that exist only in each scene? Or maybe destroy old game managers and let the new ones from the new scenes take over instead of the other way around.
     
  3. SimpleGiant

    SimpleGiant

    Joined:
    Dec 22, 2013
    Posts:
    47
    [IOTE="DWilliams, post: 2365804, member: 750073"]Maybe separate out the button functionality into scripts that exist only in each scene? Or maybe destroy old game managers and let the new ones from the new scenes take over instead of the other way around.[/QUOTE]
    I thought about scripting each scene individualy. But that doesn't seem like the proper way to do it.

    If I delete the old GameManager and keep the new one, my music will reset after each scene. I don't want that. I could make a game object that is not the game manager that plays music, if that's my only option.

    Its important that I use a gamemanager beacaus I want to teach others how to use it.

    If