script not working on multiple objects

created a simple cube and applied a material ad some how i managed to write a script to change the color of that material when a GUI button is pressed and its working fine… Then created a capsule in the same scene then applied same script on it its working for Capsule but not for my previous game object then applied on a new cube then it stops working for last two game objects…

done by defining a variable Texture_Index, when i manually change the texture index value for each object(in run time) its working,but not working when GUI button is pressed…

here my uJS script :

#pragma strict

var TextureIndex : int;

function OnGUI()
{

 GUI.Box (Rect (10,400,100,100), "Box Texture");

 //1st button

 if (GUI.Button (Rect (20,425,80,20), "1")) {
       
    TextureIndex = 0;
    }


 if (GUI.Button (Rect (20,450,80,20), "2")) {
   
    TextureIndex = 1;
    }

 }

 function Update()
 {

 if(TextureIndex == 0)
 {

 //color code = rgb value devided by 255 :)73 32 3 255

 renderer.materials[0].color = Color.blue;
 }

 else if (TextureIndex == 1)
 {

 renderer.materials[0].color = new Color (73/255F,32/255F,3/255F,1F) ;
 }
}

Besides the fact that this is not a C# script but Javascript, if you’re using the same script for two objects then what you’ll see is the GUI buttons for both objects displayed at the same position so you will be able to change the color of only one of them because the other’s buttons are behind and by the way cannot be clicked. To use the same script you should at least be able to set the buttons position from inspector, an alternate way would be to have a Renderer object in the class called for example “target” and attach it to an empty game object so this way you could drag&drop the object that you want to change as well as assign it programmatically in your code.

using this code to solve my problem but showing error (24,48): BCE0044: unexpected char: 0x201C.

what does it means?? confused :confused:
pragma strict

var TextureIndex : int;

var coloredItem;

var object : GameObject;

function OnGUI()

{

GUI.Box (Rect (10,400,100,100), “Box Texture”);

if(GUI.Button (Rect (20,425,80,20), “red”))

{

print(“zooo”);TextureIndex = 0;

}

if (GUI.Button (Rect (20,450,80,20), “blue”))

{

print(“2ooo”);TextureIndex = 1;

}

}

function Update()

{

if(TextureIndex == 0)

{

coloredItem =GameObject.FindGameObjectsWithTag(“circle”); }

else if (TextureIndex == 1)

{

coloredItem =GameObject.FindGameObjectsWithTag(“sphere”);

}

if(coloredItem!=null)

{

for (var respawn:GameObject in coloredItem)respawn.renderer.material.color=Color.blue;

}