Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 Rachel570 · Sep 23, 2016 at 11:44 AM · unity 5getcomponentslidermusicpersistent

Unity: Attaching a volume control slider that doesn't always exist, to another object.

Hello everyone, I am really new to Unity and have been trying to create a small game. In this game there is an options menu, which contains two sliders, one for the background music volume, and one for the SFX volume. I created the options menu within it's own scene, and have a persistent empty object which plays the game's music. The music player uses this simple C# script:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class musicVolume : MonoBehaviour
 {
     public Slider musicControlSlider;
     public AudioSource backgroundMusic;
     void Start()
     {
         backgroundMusic.Play();
 
     }
 
     void Update()
     {
 
         {
             backgroundMusic.volume = musicControlSlider.value;
 
         }
     }
 }

While this does successfully keep the music playing at whatever the user set in the options menu with the slider, I noticed a couple serious issues, and have been unable to resolve them.

Firstly, when I change scenes the music control slider is set to missing, as one would expect, however if I return to the options menu, the slider becomes set to "None" rather than what I graphically set it to (MusicSlider (Slider)).

Secondly, I am unable to graphically reset the slider while play mode is enabled in the editor.

Is there any way to detect the musicslider (MusicSlider), which is a child of optionsMenu, Canvas, optionsManager in the scene options whenever musicprefab (the background music object) enters the scene? That is I want this to happen whenever musicprefab enters the scenealt text

Rather than this alt text

Thank you.

expectedoutput.png (8.9 kB)
currentoutput.png (8.3 kB)
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How long would it take to make a 2d game? 0 Answers

cant slide GUI slider 0 Answers

What is the diffrence between Reference and GetComponent ? 1 Answer

How do I fix my game after API failing to update my scripts 2 Answers

UI Slider when not interactable changes color 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