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 /
  • Help Room /
This question was closed Dec 12, 2015 at 10:51 PM by mtoskamp for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by mtoskamp · Dec 11, 2015 at 02:30 AM · audioaudiosourcenot workingplay

Play audio once not working

Hi there,

I'm encountering a problem with my audio clip. It will not play at all unlike the others that I've been working with.

Everything else in my script is working and I'm starting to wonder if it is the Update function that overwrites it multiple times.

Anyone with an idea or perhaps solution for this problem? I've been looking around but didn't find anything that would solve it.

Here is the code: using UnityEngine; using System.Collections; using UnityEngine.UI;

 public class CountDown : MonoBehaviour {
     
     public float timeRemaining = 119f;
     public bool isStarted = false;
     
     private float minutes;
     private float seconds;
 
     public AudioSource VoiceFail;
 
     public Gamemaster Master;
     
     public void startTimer ()
     {
         isStarted = true;
     }
 
     void Update()
     {
         if (!isStarted) return;
 
         timeRemaining -= Time.deltaTime;
 
         minutes = Mathf.Floor (timeRemaining / 60);
         seconds = timeRemaining % 60;
 
         if (timeRemaining < 0)
         {
             minutes = 0;
             seconds = 0;
         }
 
         GetComponent<Text>().text = minutes.ToString ("0") + ":" + seconds.ToString("00");
 
         if (timeRemaining < 0)
         {
             StartCoroutine (Fail());
         }
     }
 
     private IEnumerator Fail ()
     {
         yield return new WaitForSeconds (0f);
         VoiceFail.Play();
         yield return new WaitForSeconds (15f);
         Master.Gameover(); // GAME OVER AFTER 120 SECONDS AND PLAYER DID NOT FINISH TASKS
         yield break;
     }
 }
 

Thank you in advance for replying!

Comment
Add comment · Show 1
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 mtoskamp · Dec 12, 2015 at 10:50 PM 0
Share

Fixed the code myself 2 days ago, but did not find the time to reply on it and close the question.

So here it is. using UnityEngine; using System.Collections; using UnityEngine.UI;

 public class CountDown : $$anonymous$$onoBehaviour {
     
     public float timeRemaining = 119f;
     public bool isStarted = false;
     
     private float $$anonymous$$utes;
     private float seconds;
 
     public AudioSource VoiceFail;
 
     public Gamemaster $$anonymous$$aster;
     
     public void startTimer ()
     {
         isStarted = true;
     }
 
     void Update()
     {
         if (!isStarted) return;
 
         if (timeRemaining > 0) 
             timeRemaining -= Time.deltaTime;
 
         if (timeRemaining < 0)
         {
             $$anonymous$$utes = 0;
             seconds = 0;
 
             StartCoroutine (Fail());
             timeRemaining = 0;
         }
 
         $$anonymous$$utes = $$anonymous$$athf.Floor (timeRemaining / 60);
         seconds = timeRemaining % 60;
 
         GetComponent<Text>().text = $$anonymous$$utes.ToString ("0") + ":" + seconds.ToString("00");
     }
 
     private IEnumerator Fail ()
     {
         yield return new WaitForSeconds (0f);
         VoiceFail.Play(); // NOT WOR$$anonymous$$ING YET!!! 
         yield return new WaitForSeconds (15f);
         $$anonymous$$aster.Gameover(); // GA$$anonymous$$E OVER AFTER 120 SECONDS AND PLAYER DID NOT FINISH TAS$$anonymous$$S
         yield break;
     }
 }

It was kind of a idiotic error that I made. The code should explain itself, but if your gonna use it and you don't know how, feel free and pm me I'll see if I can explain it further to you.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

33 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 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.play does not work 1 Answer

audio is not playing during IEnumerator 1 Answer

Play a variety of audio source objects from a for loop 2 Answers

Upon hitting Play, my character creates a new Audio Source Component 0 Answers

Audio is cut in script 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