audio - Sound won't play at a specific time in unity -


i trying make sound play timer goes 3, 2, 1.

my timer starts @ ten , has 3 second delay. if use following code:

    if (tl.mycooltimer == 10)     {         print("play sound");         myaudiosource.play();     } 

it plays beep on , on again until game starts , counter goes below 10.

if use code:

    if (tl.mycooltimer == 3)     {         print("play sound");         myaudiosource.play();     } 

it doesn't play sound @ all. doesn't print print statement.

i literally changed number. not sure why isn't working.

i have tried setting 3f see if float issue.

timer scripts

this starting timer. counts down 3 (then game starts)

public text startgametimertext;  public float startgametimer = 3;  public void start () {     startgametimertext = getcomponent<text> (); }   public void update () {      startgametimer -= time.deltatime;     startgametimertext.text = startgametimer.tostring ("f1");      if (startgametimer < 0) {         gameobject.find ("gamestarttimer").setactive (false);     }  } 

this game timer starts @ 10 , counts down 0.

public startgametimer gt;  //this script other timer on  public text timertext;  public float mycooltimer = 10;  public void start () {     timertext = getcomponent<text> (); }  public void update () {     if (gt.startgametimer > 0) {         mycooltimer = 10;     } else {         mycooltimer -= time.deltatime;         timertext.text = mycooltimer.tostring ("f1");     } } 

thanks joe help. here final answer. know hacked, haven't figured out invoke thing yet. when set kept playing entire time @ "3", need make play once.

private audiosource myaudiosource; public bool issoundplayed;  void start() {     myaudiosource = getcomponent<audiosource>();     issoundplayed = false; }  void update() {     if((int)tl.mycooltimer == 3)     {         if (issoundplayed == false)         {             myaudiosource.play();             issoundplayed = true;         }         return;     }     if ((int)tl.mycooltimer == 2)     {         if (issoundplayed == true)         {             myaudiosource.play();             issoundplayed = false;         }         return;     }     if ((int)tl.mycooltimer == 1)     {         if (issoundplayed == false)         {             myaudiosource.play();             issoundplayed = true;         }         return;     } } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -