- Home /
Can I switch scene on a specific time?
Hi! =)
I'm new to this program and wondering if I can switch from one scene to another on a specific time, like after 4-5sec and how do i do it? What scripts do I use and so on.
__
And in these kinds of cases can i make it switch when a song has played for some seconds?
(Ps:) Or even better: Can I switch picture after a few sec on my plane or texture?
Thanks alot.
Using Unity2.6(Not Pro)
I like this program alot and want to continue useing it :)
First time ever I making a game so i appreciate all help i can get :)
Sorry if my English is bad... :(
Answer by spinaljack · Sep 18, 2010 at 02:34 PM
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); } }
Answer by MetaliZeR · Sep 19, 2010 at 11:17 AM
Ok, when i use the script it loads my second scene immediately and just skips my first one... What am I doing wrong with the script? I want it to load scene2 when the song in scene1 is complete. Where do i put this script->
// Loads the level with index 0
Application.LoadLevel (2);
In this script-> to make it load scene2 when song is completed?
var changeLevelFlag : boolean;
function Update(){ if(!audio.isPlaying && changeLevelFlag){ // do something when the audio isn't playing // like change scenes after a tune } }
Thanks Again.
Your answer
Follow this Question
Related Questions
Cannot close/unload a scene that is open in editor during playmode (using C# code)? 3 Answers
Add Menu to Unity Roguelike Example 0 Answers
UnloadSceneAsync() does not seem to work with additive scenes. 1 Answer
Access loading screen scene components from Main Menu? 1 Answer
Particular scene loads fine in the Unity Editor, but unable to load in the executable? 0 Answers