How to check an entire list and apply conditions.

Hello and apologizes regarding the title

I have no idea how to put this better.
My question is how to manage the following better:

I have 15 game objects instantiated randomly.
Each object when clicked, will direct you to a scene (15 scenes in total)

How to attach each load scene to each game object efficient when clicked ?

My code idea is this :

void SettingUpLocations()
	{
		if(Input.GetMouseButtonDown(0))
		{
			
		//SETUP EACH LOCATION
		if (clickedGmObject.name == "BattleLocation1(Clone)")
		{
			Application.LoadLevel ("FirstLevel");
		}
		}
	}  

I will iterate this 14 more times. I am pretty sure there is a more effective way of doing this. Any ideas ?

BTW I also have a list of the spawned prefabs made like this :

prefabTransforms.Add(Instantiate(spawnThis*.transform, spawnPoints[r].transform.position , spawnPoints[r].transform.rotation) as Transform);*

You can’t use Input.GetMouseButton and expect it will know which object you clicked. It gathers mouse event regardless where it is clicking.

Make a class like this and name it SettingUpLocations.js (or whatever you wish):

#pragma strict
public var levelName = "";

function OnMouseUp () {
	Application.LoadLevel(levelName);
}

Add it to each of your game objects and set Level Name as you wish in the Inspector. Be sure the objects have colliders on them.

P.S.: You could name the question something like “How to check for mouse clicks on many different objects”. Also, next time, try researching and looking at code on wiki first. Lots to learn there! :wink: