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 PJEstrada006 · Mar 27, 2015 at 05:03 PM · soundaugmented-reality

Problem playing multiple sounds on a scene

Hello,

I´m developing an Augmented Reality piano with Vuforia and Unity 4.6. The app will be a game where the mobile phone will say a note, for example :"C" and the user will have 5 seconds to play the note in a paper piano with virtual buttons.

The problem I´m having is that I´m not getting the sounds of the piano keys when I press a button. I do enter the desired case in the switch statement, but no sound is played.Neither the play() methods on the Update function or the OnButtonPressed() are playing. However on the method generarNota(). I always listen the sound of the phone saying the note.

This is my code:

 public class ButtonControl : MonoBehaviour,IVirtualButtonEventHandler {
     public AudioSource c;
     public AudioSource cSharp;
     public AudioSource d;
     public AudioSource dSharp;
     public AudioSource e;
     public AudioSource f;
     public AudioSource fSharp;
     public AudioSource g;
     public AudioSource gSharp;
     public AudioSource a;
     public AudioSource aSharp;
     public AudioSource b;
     public AudioSource correctSound;
     public AudioSource incorrectSound;
     public AudioClip cv;
     public AudioClip cSharpv;
     public AudioClip dv;
     public AudioClip dSharpv;
     public AudioClip ev;
     public AudioClip fv;
     public AudioClip fSharpv;
     public AudioClip gv;
     public AudioClip gSharpv;
     public AudioClip av;
     public AudioClip aSharpv;
     public AudioClip bv;
     public AudioSource c2;
     public bool gameOn;
     string currentNote; //Nota genereada por el sistema
     string inputNote; //Nota presionada por el usuario
     public float waitTime; //Tiempo de espera entre notas
     public float resetWait; // Para reiniciar el tiempo de espera
     public int totalNotes;
     public int correctNotes;
     public int incorrectNotes;
     bool firstNote;
     bool beingHandled;
     public bool blackNotes;
     bool notePressed;
     //Use this for initialization
     void Start () {
         c.PlayOneShot(c.clip);
         blackNotes = false;
         this.notePressed = false;
         beingHandled = false;
         currentNote="NONE";
         waitTime = 0;
         firstNote = true;
         VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
         for (int i = 0; i < vbs.Length; ++i) {
             // Register with the virtual buttons TrackableBehaviour
             vbs[i].RegisterEventHandler(this);
         }
 
     }
     void generarNota(){
         if (blackNotes) {
                         int num = Random.Range (1, 13);
                         //StartCoroutine ("waitTimeDelay");
                         switch (num) {
                         case 1:
                                 Debug.Log ("Se genero C");
                                 int a = 0;
                                 currentNote = "C";
                                 audio.clip = this.cv;
                                 audio.PlayDelayed (0.5f);
     //this.aSource.PlayOneShot(this.cv);
                                 break;
                         case 2:
                                 Debug.Log ("Se genero C#");
                                 currentNote = "C#";
                                 audio.clip = this.cSharpv;
                                 audio.PlayDelayed (0.5f);
                                 break;
                         case 3:
                                 Debug.Log ("Se genero D");
                                 currentNote = "D";
                                 audio.clip = this.dv;
                                 audio.PlayDelayed (0.5f);
                                 break;
                         case 4:
                                 Debug.Log ("Se genero D#");
                                 currentNote = "D#";
                                 audio.clip = this.dSharpv;
                                 audio.PlayDelayed (0.5f);
                                 break;
                         case 5:
                                 Debug.Log ("Se genero E");
                                 currentNote = "E";
                                 audio.clip = this.ev;
                                 audio.PlayDelayed (0.5f);
                                 break;
                         case 6:
                                 Debug.Log ("Se genero F");
                                 currentNote = "F";
                                 audio.clip = this.fv;
                                 audio.PlayDelayed (0.5f);
                                 break;
                         case 7:
                                 Debug.Log ("Se genero F#");
                                 currentNote = "F#";
                                 audio.clip = this.fSharpv;
                                 audio.PlayDelayed (0.5f);
                                 break;
                         case 8:
                                 Debug.Log ("Se genero G");
                                 currentNote = "G";
                                 audio.clip = this.gv;
                                 audio.PlayDelayed (0.5f);
                                 break;
                         case 9:
                                 Debug.Log ("Se genero G#");
                                 currentNote = "G#";
                                 audio.clip = this.gSharpv;
                                 audio.PlayDelayed (0.5f);
                                 break;
                         case 10:
                                 Debug.Log ("Se genero A");
                                 currentNote = "A";
                                 audio.clip = this.av;
                                 audio.PlayDelayed (0.5f);
                                 break;
                         case 11:
                                 Debug.Log ("Se genero A#");
                                 currentNote = "A#";
                                 audio.clip = this.aSharpv;
                                 audio.PlayDelayed (0.5f);
                                 break;
                         case 12:
                                 Debug.Log ("Se genero B");
                                 currentNote = "B";
                                 audio.clip = this.bv;
                                 audio.PlayDelayed (0.5f);
                                 break;
                         }
                         this.totalNotes++;
                 } 
         else {
             int num = Random.Range (1, 8);
             //StartCoroutine ("waitTimeDelay");
             switch (num) {
             case 1:
                 Debug.Log ("Se genero C");
                 int a = 0;
                 currentNote = "C";
                 audio.clip = this.cv;
                 audio.PlayDelayed (0.5f);
                 //this.aSource.PlayOneShot(this.cv);
                 break;
 
             case 2:
                 Debug.Log ("Se genero D");
                 currentNote = "D";
                 audio.clip = this.dv;
                 audio.PlayDelayed (0.5f);
                 break;
 
             case 3:
                 Debug.Log ("Se genero E");
                 currentNote = "E";
                 audio.clip = this.ev;
                 audio.PlayDelayed (0.5f);
                 break;
             case 4:
                 Debug.Log ("Se genero F");
                 currentNote = "F";
                 audio.clip = this.fv;
                 audio.PlayDelayed (0.5f);
                 break;
 
             case 5:
                 Debug.Log ("Se genero G");
                 currentNote = "G";
                 audio.clip = this.gv;
                 audio.PlayDelayed (0.5f);
                 break;
 
             case 6:
                 Debug.Log ("Se genero A");
                 currentNote = "A";
                 audio.clip = this.av;
                 audio.PlayDelayed (0.5f);
                 break;
 
             case 7:
                 Debug.Log ("Se genero B");
                 currentNote = "B";
                 audio.clip = this.bv;
                 audio.PlayDelayed (0.5f);
                 break;
             }
             this.totalNotes++;
 
 
         
         }
     
     }
     void waitTimeDelay(){
 
         
     }
     // Update is called once per frame
     void Update () {
         if (this.gameOn) {
             if(this.waitTime>0){
                 this.waitTime-= Time.deltaTime;    
                 //Verificamos el boton. Si esta presionado el correcto sumamos a las notas correctas
                 if(inputNote==this.currentNote){
                     //audio.clip = this.correctSound;
                     //audio.Play();
                     correctSound.Play();
                     this.correctNotes++;
                     inputNote ="NONE.";
                     this.waitTime = resetWait;
                     this.generarNota();
 
                 }
                 else if(inputNote!= "NONE." && inputNote != this.currentNote){
                     //Si la nota es incorrecta, agregamos uno a las incorrectas y generamos una nueva nota
                     //audio.clip = this.incorrectSound;
                     //audio.Play();
                     incorrectSound.Play();
                     this.incorrectNotes++;
                     inputNote ="NONE.";
                     this.generarNota();
                     this.waitTime = resetWait;
                 }
                 //Generamos nueva nota
 
                 //Reiniciamos 
 
             }
             else{
                 //Reiniciamos el tiempo 
                 this.waitTime = this.resetWait;
                 if(!this.firstNote){
                     // Como no presiono nada, nota erronea
                     this.incorrectNotes++;
                     incorrectSound.Play();
                     //audio.clip = this.incorrectSound;
                     //audio.Play();
             
                     //this.aSource.PlayOneShot(this.incorrectSound);
 
 
 
                 }
                 else{
                     this.firstNote = false;
 
                 }
                 //generamos una nueva nota
                 this.generarNota();
 
 
             }
                 
         
         }
 
         
     }
 
     public void OnButtonPressed(VirtualButtonAbstractBehaviour vb){
         if (blackNotes&&!notePressed) {
 
         switch (vb.VirtualButtonName) {
             case "buttonC":
                     this.inputNote = "C";
                     //audio.PlayOneShot (c);
                     break;
             case "buttonCSharp":
                     this.inputNote = "C#";
                     //audio.PlayOneShot (cSharp);
                     break;            
             case "buttonD":
                     this.inputNote = "D";
                     //audio.PlayOneShot (d);
                     break;
 
             case "buttonDSharp":
                     this.inputNote = "D#";
                     //audio.PlayOneShot (dSharp);
                     break;
 
             case "buttonE":
                     this.inputNote = "E";
                     //audio.PlayOneShot (e);
                     break;
             case "buttonF":
                     this.inputNote = "F";
                     //audio.PlayOneShot (f);
                     break;
             case "buttonFSharp":
                     this.inputNote = "F#";
                     //audio.PlayOneShot (fSharp);
                     break;
             case "buttonG":
                     this.inputNote = "G";
                     //audio.PlayOneShot (g);
 
                     break;
             case "buttonGSharp":
                     this.inputNote = "G#";
                     //audio.PlayOneShot (gSharp);
                     break;
             case "buttonA":
                     this.inputNote = "A";
                     //audio.PlayOneShot (a);
                     break;
             case "buttonASharp":
                     this.inputNote = "A#";
                     //audio.PlayOneShot (aSharp);
                     break;
 
             case "buttonB":
                     this.inputNote = "B";
                     //audio.PlayOneShot (b);
                     break;
             case "buttonC2":
                     this.inputNote = "C";
                     //audio.PlayOneShot (c2);
                     break;
             }
             notePressed=true;
                 } 
         else if(blackNotes==false && notePressed==false){
 
             switch (vb.VirtualButtonName) {
             case "buttonC":
                 this.inputNote = "C";
                 Debug.Log ("Se Presiono C");
                 c.Play();
                 break;        
             case "buttonD":
                 this.inputNote = "D";
                 d.Play();
                 Debug.Log ("Se Presiono D");
                 break;
                 
             case "buttonE":
                 this.inputNote = "E";
                 e.Play();
                 Debug.Log ("Se Presiono E");
                 break;
             case "buttonF":
                 this.inputNote = "F";
                 f.Play();
                 Debug.Log ("Se Presiono F");
                 break;
             case "buttonG":
                 this.inputNote = "G";
                 g.Play();
                 Debug.Log ("Se Presiono G");
                 break;
             case "buttonA":
                 this.inputNote = "A";
                 a.Play();
                 Debug.Log ("Se Presiono A");
                 break;
                 
             case "buttonB":
                 this.inputNote = "B";
                 b.Play();
                            Debug.Log ("Se Presiono B");
                 break;
             case "buttonC2":
                 this.inputNote = "C";
                 c2.Play();
                 Debug.Log ("Se Presiono C2");
                 break;
             }
 
             notePressed=true;
         }
     }
         //If para cada tecla del piano
 
         //audio.PlayOneShot(myClip);
 
         //Comparamos si las notas son iguales.
         //Si son iguales, sonido correcto+generar una nueva nota+sumar contador de puntos
 
 
         //Si no son iguales--> sonido de error+ terminar juego
 
 
 
 
     public void OnButtonReleased(VirtualButtonAbstractBehaviour vb){
         notePressed = false;
         this.inputNote = "NONE.";
         Debug.Log ("BUTTON UNPRESSED");
 
         
         
     }
 }



Here´s also my editor screenshot so you can check that I have audioclips attached to each audio source. alt text

Can anyone help me to find where the problem is ?

1.png (406.5 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

2 People are following this question.

avatar image avatar image

Related Questions

Cloud recognition in Vuforia 0 Answers

Can an AR app contain both Huawei AR Engine and ARCore at the same time? 0 Answers

Audio Needs to stop 1 Answer

Audio Playing upon death 1 Answer

How do I add sound to a sliding door animation? 2 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