• 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 /
avatar image
0
Question by JakeLeB · Jun 10, 2014 at 12:22 AM · objectmodelmusictoggle

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.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kiwasi · Jun 10, 2014 at 12:54 AM

 gameObject.enable = false
Comment
Add comment · Show 2 · 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 JakeLeB · Jun 10, 2014 at 09:11 AM 0
Share

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.

avatar image Kiwasi · Jun 10, 2014 at 06:25 PM 0
Share

// Assign this in the inspector public GameObject monster1;

// Put this in the appropriate button code monster1.enabled = false

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 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

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

Toggling through music 1 Answer

Get all child objects within an object? 2 Answers

[Modeling] Splitting and Rejoining Objects -- Good or bad practice? 1 Answer


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