Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Mike Wong · May 28, 2014 at 10:45 PM · buildaudiotriggerexport

Trigger doesn't work in Built version

I'm using Triggers to play different BGMs in different rooms, adding a behavior to the FPS controller, as well as an audiosource to it. The code is as following:

public class NewBehaviourScript : MonoBehaviour {

 public AudioSource s;
 public AudioClip music1;
 public AudioClip music2;

 void Start () {

 }

 void Update () {

 }

 void OnTriggerEnter(Collider e){
     TestGUI.x=0;

     if (e.transform.name == "play1") {
         s.audio.Stop();
         TestGUI.x=10;
         s.audio.PlayOneShot(music1);
                     
     } else if (e.transform.name == "play2") {
         s.audio.Stop();
         TestGUI.x=20;
         s.audio.PlayOneShot(music2);
     }
 }

}

where s is given the First Person Controller's audiosource component. On entering trigger "play1", music1 would play, and same for "play2". Also, to test whether the program runs correctly, I've added another variable x, and there's a seperate GUI code TestGUI that draws a texture at x-position. (If trigger is detected, x would become 0, and if the specific zones are acknowledged, such as "play1" or "play2", then not only would music change but also would x become 10 or 20)

This runs perfectly in editor mode, changing BGM and x as I enter different zones. Problem is, after I build and run it, the BGMs cannot be changed, although a trigger is still detected (x becomes 0). The program can't determine which trigger it is, and can't enter the "if" clauses.(Hence x stays 0, but not 10 or 20)

Can somebody help me? Since this is a multiscene project, I figure it might be some problem in namespaces in different scenes? Would it be possible that after build, the e.transform.name would have some prefixes to it, so that e.transform.name=="play1" no longer works?

Or, would there be some other way to play different BGM in different rooms?

Thank you very much!!

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 JackofTraes · Mar 13, 2015 at 07:21 AM

Have you tried separating tagging the object(s) in question (collider 'e')?

Once you do this, you will check for the collider:

 // This is how you check for a tag.
 if (e.tag == "myTag") {
    // Do action here.
 }
 
 if (e.tag == "myOtherTag") {
    // Do other action here.
 }

Depending on what your plans for your project, this may or may not be the best solution. If not, I would suggest giving both trigger zones a check with a serialized int and switch statement (if you need more than two BGMs:

 [Ranger (1, 10)] // Set the range to whatever you want.
 [SerializeField]
 private int triggerType = 1;
 
 // Notice that I do not use a tag.
 // If you want certain objects to trigger it, provide tag checks.
 void OnTriggerEnter (Collider e) {
     switch (triggerType) {
         case 1:
             // Stop Audio
             // Set GUI position
             // Play BGM
             break;
         case 2:
             // Stop Audio
             // Set GUI position
             // Play BGM
             break;
         default:
             // Do nothing.
             break;
         }
 }

Hopefully this helps. At the very least, it should give you some ideas on possible solutions.

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

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

21 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

Related Questions

Distribute terrain in zones 3 Answers

How come the camera's functions doesn't work in the iOS build? 0 Answers

Diffrent On trigger exit behavoiur in game build 1 Answer

Can I have a moving shape as a trigger zone? 1 Answer

Quadruple audio fade script not working completely. Shocker. 0 Answers


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