- Home /
Enable/Disable Object and Music?
I'm making a game that has three enemies, but you can only face one at a time. Instead of making it so you click a button that loads their map I've decided to show them on the main menu.
Upon start, the first enemy is displayed by default with his theme song attached as an audiosource to the camera. I have the other two models as children objects (along with the other enemy) of the camera. I have made 3 buttons in the top left with their names in, when clicked I'd like them to show the enemy for that button.
So for example if Enemy2 is pressed, I want to hide Enemy1 from the camera and play/loop another soundtrack but if I press Enemy1 I want to change back to his model/music.
I tried using Transform but I couldn't figure out the right thing to use, as for the music I tried using playonce/loop through the code but it overlapped.
EDIT: Nevermind, I managed to get the music working now by using audio.PlayOneShot (Not sure if thats the actual code) and then using the same on "public void Awake()" I used audio.Stop() too so it's all good now. I just need to Show/Hide the models if possible.
Answer by Kiwasi · Jun 10, 2014 at 12:54 AM
gameObject.enable = false
The script isn't attached directly to the object, the C# script I'm using is attached to the Camera as it's the menu code. The objects I wish to disable are children of the camera.
// Assign this in the inspector public GameObject monster1;
// Put this in the appropriate button code monster1.enabled = false
Your answer
Follow this Question
Related Questions
can you make a prefab but without a model? 3 Answers
NullReferenceException: Object reference not set to an instance of an object 0 Answers
How to deactivate background music when I land on an object? 1 Answer
Get all child objects within an object? 2 Answers
[Modeling] Splitting and Rejoining Objects -- Good or bad practice? 1 Answer