x


how to script in different scenes?

hello. me again.

i want to know how how i can, lets say, play an animation for the camera, when it eneters another scene (using DontDestroyOnLoad).

wouldi type "if(Application.load(whatever){ play whatever}" ?

more ▼

asked Sep 16 '10 at 04:00 PM

Nathan Bennett gravatar image

Nathan Bennett
154 31 33 35

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can implement OnLevelWasLoaded on the object. It will get called every time a new level is loaded.

In the manual's code example, it checks the index of the level that was loaded to decide what to do:

function OnLevelWasLoaded (level : int) {
  if (level == 13) {
    print ("Woohoo");
  }
}

I don't recommend doing it that way- you risk breaking your game whenever you add a new scene or reorder scenes. It's usually safer to check the level's name using Application.loadedLevelName, unless you are in the habit of renaming your levels. The code is easier to read as well:

function OnLevelWasLoaded (level : int) {
  if (Application.loadedLevelName == "MainMenu") {
    // etc.
  }
}
more ▼

answered Sep 16 '10 at 04:33 PM

Bampf gravatar image

Bampf
5k 8 19 49

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3777
x717
x297
x61

asked: Sep 16 '10 at 04:00 PM

Seen: 1041 times

Last Updated: Sep 16 '10 at 04:00 PM