Hi all,
I have created a small script that spawns 6 different objects on start. I want the object that I clicked on to change color. I have assigned unique names to each object. However, when I use onMouseDown, all objects change color. How do I tell unity that I only want that specific object to change? Unfortunately, I could not find a good answer to this on the forums.
var isSelected : boolean;
var playerPrefab : Rigidbody;
var numberOfPlayers : int = 6;
function Start () {
var x : int;
for(x=0;x<numberOfPlayers; x++){
var player = Instantiate(playerPrefab, Vector3(x*2.0,0.5,0.0), transform.rotation);
player.name = "player" + x;
}
function Update(){
if(isSelected){
renderer.material.color = Color.red;
}
}
function OnMouseDown () {
isSelected = true;
}