Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
captainprice

Junior Member
Registered:
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]
Captainprice..
0
Martin

Avatar / Picture

Administrator
Registered:
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:

GameObject.Find("SoundManager").BroadcastMessage("PlaySpawnSound");


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
       spawnSound.Stop();
       spawnSound.Play();
}



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:

GameObject.Find("Music").GetComponent("AudioSource").Stop();


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]
Martin
0
Grumpy

Senior Member
Registered:
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;

Awake(){
 gameManager=this;
}


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

return(GameManager.gameManager);
}

public SoundManager GetSoundManager(){

return(GameManager.gameManager.soundManager);
}



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

This works really well for me.

 

0
ScubaBear

Junior Member
Registered:
Posts: 16
Reply with quote  #4 

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

 

http://unity3d.com/learn/tutorials/modules/intermediate/scripting/events

0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.