Edit: down below I added an alternative (better, easier, move efficient and more expandable way - if other then name you want to add way more data) way, so check that out first!
Whow, fifth answer already to a fairly simple question. What you do is you use a script to instantiate several instances of the prefab. You said the second one is the one where you want the mouse down?
Have a counter that checks how many you've instantiated
var counter : int = 0; // when you instantiate, on the next line put counter ++;
Now in your update function check if the instantiated object is the first/second/third one, if so add the script.
if(counter == 2) { cloneName.AddComponent("theClickScriptTwo");} //or 1 or 3 of course
This will add a script called theClickScript. You will first have to create a new script with that name, of course. It would look something like this, depending on what you want to happen when you click on it of course.
var myName : String;
function OnMouseDown () {
myName = name;
Debug.Log(myName);
}
I'm assuimg for this that you instantiate like this:
cloneName = Instantiate(prefabName,Vector3Position, QuaternionRotation);
Hope the problem is solved now. Because this certainly works and is easy to set up. :)
An other way, which I used myself recently, is to use arrays. You will need an array of instantiated gameobjects and an array of for instances the names you want to display. I'll assume you have n number of instantiated Objects.
var cam : Camera;
var prefab : GameObject;
var objects : Array = new Array ();
var objectNames : Array = new Array ("nameOne", "nameTwo",...,"nameN");
var objectLocations : Array = new Array (Vector3(a,b,c),Vector3(d,e,f),...,Vector3(x,y,z);
function Start () {
for(i=0;i<objectLocations.length;i++) {
newObject = Instantiate(prefab,objectLocations*,Quaternion.identity);*
*objects.Add(newObject);*
*newObject.name = "object"+i; //your inst. are now named object1,object2,...,objectn*
*}*
*} //boom, you have a sorted array of the instantiated objects, we can now reference them by number! Remember, the first entry will be i=0*
*function Update() {*
*var hit : RaycastHit;*
*if(Physics.raycast(cam.ScreenPointToRay(Input.mousePosition),cam.transform.forward,hit) && Input.GetMouseButtonDown(0)){*
*for(i=0;i<objectLocations.length;i++) {*
_if(hit.collider.gameObject == objects*) {*_
_*Debug.Log("your clicking on "+objectName*_
<em>_*//put a boolean trigger here that enables a gui window displaying the info.*_</em>
<em>_*}*_</em>
<em>_*}*_</em>
<em>_*}*_</em>
<em>_*}*_</em>
<em>_*```*_</em>
<em><em>*<p>This way of doing it may seem complicated, but you can have as many instantiations of the prefab, with as many names and positions without having to go through any trouble. I used it for instance to instantiate 11 planets from one prefab and when the mouse was over any of them it displayed a guiWindow with name/planet type/size/distance etcetera. Check it out <a href="http://www.kongregate.com/games/Josh_Amsterdam/space-exploration" rel="nofollow">here</a> if you like. </p>*</em></em>