Sign up Calendar Latest Topics

  Author   Comment  

Junior Member
Posts: 20
Reply with quote  #1 
I have prefabs of GameManager Object on which score, and game logics are attached 
and there is one Persistent gameObject which is loaded on start scene and is use with DontDestroyonload 

I wanna ask is how you guys setup your gameManager ?

and also i am having problem with playing and pausing my backgroundSound. how can do setup that ?

love you all, Happy coding [comp]

Avatar / Picture

Posts: 2,230
Reply with quote  #2 
Hey Captainprice. How are you this week. Im sorry for the late reply to your post.
In my game before I used a Sound Manager to play all sounds in the game so that they were only played once. So for example if there are many objects in the scene, and each one needs to play a sound, they would call something like this:


Then in the SoundManager.js file in the SoundManager game object this is the function that would be called:

var spawnSound : AudioSource;

function PlaySpawnSound()
       //make the sound stop and play each time so it sounds like more objects are spawning

For a game manager script I didn't really do this in the code I used before. But I think generally it has the same principle. Just call the different game state inside a GameManager script depending on what happens in the game.

For background sound / music I usually just start it in the 1st scene. So the first scene that loads I have a game object called Music. I add an AudioSource component to it and add the music wav file. Then I check the 'loop' box, and the 'play on awake' box. Also I add a script to the game object called DontDestroyOnLoad just so it stays persistent through out the game. To stop the music you can do this I think:


I'm not sure if that code above with work but that's the general approach I would take.

I hope this helps, let me know how it goes.
Chat soon [smile]

Senior Member
Posts: 318
Reply with quote  #3 

I set up my GameManager in a similar way to how you do it. Then I do this:

public static GameManager gameManager;


After that I can reference the one unique GameManager script in any script by typing GameManager.gameManager.

I then attach all my other managers to the GameManager script. Then I can call them by typing GameManager.gameManager.soundManager.

What I've also found very useful is to create a Game class that everything derives from where I put really useful commonly used functions. So every script in my game is a child to a script called GameMaster.

In that I can put scripts like this:

Public GameManager GetGameManager(){


public SoundManager GetSoundManager(){


So that way if I type GetSoundManager() anywhere in my scripts I have access to the soundManager.

This works really well for me.



Junior Member
Posts: 16
Reply with quote  #4 

Hi! I know it's a bit late but, maybe this could be useful..

Previous Topic | Next Topic

Quick Navigation:

Easily create a Forum Website with Website Toolbox.