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 martensen7 · Sep 02, 2013 at 10:02 AM · animationsound

Sound is not playing.

Hi all,

I hope I will be clear enough about my problem. I am creating very simple app or game(on android) where u just type the word and the object connected to that word will disappear(fade animation) and the sound will be played.

How it should work: In the app I touch the screen the native keyboard come up. I type the word the object connected to that word will disappear and the sound clip has been played along with the animation.

Reality : I touch the screen the keyboard come up I type the word, I hit done, the native keyboard disappear, the object disappear animation is played correctly but there is no sound. When I touch screen again the native keyboard come up and the sound clip is played and I dont know why.

I created a empty gameobject and put sound clip to it.Thats how I am trying to play the sound.

Here is the code : #pragma strict

 function Start () {
 
 }
 var putString:String="";
 var inputString:String="";
 var keyboard:TouchScreenKeyboard;
 var inv=new Array("laptop","mug","table");
 
 
 function wordLoop(){
 
 for( var value : String in inv){
 
 if(inputString==value){
 
 GameObject.Find(value).animation.Play("fade");
 //Destroy(GameObject.Find(value),1);
 GameObject.Find("sound").audio.Play();
 //yield WaitForSeconds(1);
 
 
 
 }
 }
 }
 function Update(){
 
 
 if(Input.touchCount>0){
 
 keyboard=TouchScreenKeyboard.Open(putString);
 }
 if(keyboard.done){
 
 inputString=keyboard.text;
 wordLoop();
 
 }
    
 
 }

Can you please help me where is the problem that the sound is not played along with the animation but after the keyboard comes up?

Thanks in forward.

Martin.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ZenithCode · Sep 02, 2013 at 12:41 PM

The problem is that you're trying to play the Audio once every frame. In the update() or the wordLoop() check if audio is playing first.

Suggestion: Put the GameObject.Find in the Start() because you don't need to do this every frame either.

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 martensen7 · Sep 02, 2013 at 09:10 PM 0
Share

$$anonymous$$any thanks for your quick reply guys I will try it out.

avatar image ZenithCode · Sep 02, 2013 at 09:16 PM 0
Share

Please accept the answers if they helped you! :-)

avatar image
0

Answer by citizen_rafiq · Sep 02, 2013 at 10:40 AM

//Use a script to manage your sound

public class SoundManager : MonoBehaviour {

 private AudioClip backgroundMusic;
 public AudioClip BackgroundMusic{
     set{
         backgroundMusic=value;
     }
     get{
         return backgroundMusic;
     }
 }
 
  void Awake(){
     
     this.BackgroundMusic = Resources.Load("Sounds/background_music", typeof(AudioClip))as AudioClip;
     if(!this.BackgroundMusic){
         Debug.LogError(" background_music not found or name shoud be background_music");
     }
     
 }
 
 public void PlayBackgroundMusic(){
         audio.clip=this.BackgroundMusic;
         audio.volume=Constants.volBackgroundMusic;
         audio.Play();
         audio.loop=true;
 }
 
 public void StopBackgroundMusic(){
         if(audio.isPlaying){
             audio.Stop();
         }
 }
 

}

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

17 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

Related Questions

Can you fix my code? (Audio for doors) 2 Answers

Animation and sound help 0 Answers

Play sound on trigger, sound is coming from the trigger 1 Answer

Totally new noob to mecanim and unity itself - Trigger animation? 0 Answers

Can the animation editor create local rotational data? 3 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