Scene Linking

var availableLevels : String[];var windowWidth : int = 200;
var windowHeight : int = 200;
private var showMenu : boolean = false;

function TriggerAction () {  //Replace TriggerAction with your desired means of triggering the menu.    showMenu = true;
}

function OnGUI () {    if (showMenu) {        GUI.Window(0,Rect((Screen.width / 2) - (windowWidth / 2),   
(Screen.height / 2) - (windowHeight / 2),                         windowWidth,                         windowHeight),                    LevelSelect,                    "Select a level!");  //Creates a window with ID 0 in the center of the screen using the function LevelSelect with the title, "Select a level!"    }
}

function LevelSelect (id : int) {    
for (var levelName : String in availableLevels) {        
if (GUILayout.Button(levelName)) {            Application.LoadLevel(levelName);        
}    
}    
if (GUILayout.Button("Cancel")) {  //Gives the player the opportunity to back out of the menu.        showMenu = false;    }
}

So I got this code from someone else for multiple choice locations.

But what I want to know, is can I have seperate locations, say 2 on one object. 3 on another location. Enter a new scene, that object has 1 or 2, another 3, etc.

I am building a space project and want the player to be able to travel to other star systems via a phase gate. But each gate I want more then just one location…can this be done? If so, how can the above code be altered to get the effect?

Absolutely, if I understand what you’re asking right, then you don’t need to change the code at all. Just pass in a different set of values in availableLevels, for each gate.

Alright, will give that a try and see what happens tonight! I will reply with the results…

So I tested the code, and I got:

Level could not be loaded because its not added to the build settings. It is, I looked.

So there has to be an error in the code or something, and I cannot find it…

grrr…help please…

Nevermind I figured out the problem and works quite nicely!

Alright,

So I ran into another bit of a problem with the linking.

I know that when creating a new level (new star system in my case) you place the player down where they will arrive/start.

Well going to the new star system works beautifully. My question is, when I return back through the gate, I start where the player first starts on the otherside of the system.

How can I correct this to get the player to actually arrive at each gate?

It would help future users immensely if you were to explain what you figured out, thanks.

In the inspector’s tab, once you add the script to the jumpgate, click the little arrow next to available levels. Set the number to how many you want to link to. It will show: 0, 1, 2, etc. In the blank spot off to the right of each number, you can click the spot, and type in the name of the level.

It will now show up on the GUI once entering the jumpgate!! :slight_smile:

Anyone have ideas on this?

Create an invisible “Spawn Point” prefab (You can assign a gizmo to an empty game object to achieve it)

When the scene starts, transfer the player to the spawn point like for example “transform.position = spawnPoint.transform.position”

As soon as you leave the scene, transfer the Spawn Point to wherever you like the player to appear when he arrives back to that star system.

And voila, as it will use the script to transfer the player to the spawn point each time a scene starts, it’s only a couple of lines of code to achieve the wanted effect. Just make sure you have a spawn point prefab in all the scenes, where the player will appear.

This is what I’ve used in the past and it works like a charm. PM me if you need more help.

Will this not affect the starting point, when first loading the game?