Quantcast
Channel: Answers for "Can I switch scene on a specific time?"
Viewing all articles
Browse latest Browse all 4

Answer by spinaljack

$
0
0

Thems a lot of questions for one post...

To do something after a song has finished playing:

var changeLevelFlag : boolean;

function Update(){
   if(!audio.isPlaying && changeLevelFlag){
      // do something when the audio isn't playing 
      // like change scenes after a tune
   }
}

To cause a function to yield control for a few seconds (minimum 1 frame):

function SomeFunction(){
   print("Current Time is " + Time.time);

   yield WaitForSeconds(3);

   print("Current Time is " + Time.time);
}

To use a time stamp to make something happen some time after an event:

var timeStamp : float;
var buttonFlag : boolean;

function PushButton(){
   timeStamp = Time.time;
   buttonFlag = true;
}

function Update(){
   if(buttonFlag && Time.time-timeStamp > 3){
      // do something 3 seconds after PushButton
   }
}

There are many more examples but you should take a look at some game tutorials to practice your general coding knowledge.

EDIT:

Using your example:

function Start(){
   audio.Play();
}

function Update(){
   if(!audio.isPlaying){
      Application.LoadLevel(1);
   }
}

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>