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 fancytank · Dec 25, 2013 at 10:08 PM · audiosourceaudioplay

AudioClip doesn't play sound

alt text

Hello, again. I'm not a native English speaker, so please be generous with my grammatical faults.

I want to play two audio clip as background music.
The one(names 'audioNormal') has to play as game start, the other(names 'audioFaster') has to play when time remains less than half.

"audioNormal" clip is attached to Main Camera.
I thought "audioFaster" clip should be also atteched to Main Camera, too.
However, it never works.

Here's my script and it is also attached Main Camera.
(The Image I attached is an Inspector window of Main Camera.)

 #pragma strict
 @script RequireComponent(AudioSource)
 
 var audioNormal:AudioClip;
 var audioFaster:AudioClip;
 var time: GameObject;        // need to get time infomation
 function Start ()
 {
     audio.clip = audioNormal;
     audio.Play();
     time = gameObject.Find("GUIs/txtTime");
     Debug.Log("1");
 }
 
 function Update ()
 {
     if(time.GetComponent(TimeGUI).startTime-Time.time < 31.0)
     {
         Debug.Log("2");
         audio.Stop();
         audio.clip = audioFaster;
         Debug.Log("3");
         audio.Play();
     }
 }

I used Debug.Log script to check the state of communication between two other scripts, and all of them have printed well.
Of course audio files doesn't have any problem.

Now I am so confused.
What did I wrong? It's too hard to find by myself.
Please help me.

maincamera.gif (50.9 kB)
Comment
Add comment · Show 2
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 Statement · Dec 26, 2013 at 03:16 AM 0
Share

Do you get any audio at all?

avatar image fancytank · Dec 26, 2013 at 05:16 AM 0
Share

No, only second audio clip('audioFaster' in my script) doesn't play sound. 'audioNormal' plays well.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by emc233 · Dec 25, 2013 at 10:33 PM

you cant say: audio.clip = audioNormal;

instead you should say: this.gameObject.audio.clip = audioNormal; this.gameObject.audio.Play();

Comment
Add comment · Show 3 · 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 fancytank · Dec 26, 2013 at 01:19 AM 0
Share

Oh..I'm afraid to say, but it doesn't work. The reason I wrote that way, because it is in the Unity Script Reference. Though, thank you for the answer.

avatar image Statement · Dec 26, 2013 at 03:14 AM 0
Share

This answer is not really doing anything else than the code that @fancytank already have written. this.gameObject.audio vs audio achieves nothing else than perhaps makes the code read out a bit more explicit about your intentions. It's just a more verbose way of asking for the same thing.

avatar image emc233 · Dec 27, 2013 at 01:52 AM 0
Share

On second thought, It looks like you want to background music for your level. You should make it a 2-d sound. I am not sure if that will help, but it is just a thought. You can also check off play on awake...

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

20 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

Related Questions

Audio not playing 1 Answer

2nd Audio Clip Not Playing 0 Answers

How to make audio not playing repeatedly? 1 Answer

Best way to change looping sound 2 Answers

How can I play a sound effect many times without cutting the last sound effect? 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