many objects with same script but need to make changes locally

hey,
been messing (up) with this for a while.
I have x amount of objects being spawned with the same script.
In the script I have a variable that should check if the particular object is active.
nevertheless every object becomes active.
I tried both static var and public var but no luck so far.

some objects will have the same name (e.g. sphere(clone)), some not.

In the script below I wish to change the material for the object being clicked:

function Awake () {
	
	materialOriginal = this.gameObject.renderer.material;
}
var objectMode : boolean = false;
public var materialOriginal : Material;
public var materialWhenObjectActive : Material;
function Update () {
	if(objectMode == true  tag=="object")
	{
		materialWhenObjectActive = modeControl.activeObject.renderer.material;
	}
	else
	{
		this.gameObject.renderer.material = materialOriginal;
	}
	

}

Right now I wish to use the color shift as visual feedback that the touch on the particular obj is performed…

hope to get some pointers, dunno why this is going wrong… too much coffee?
Best,
Krodil

how are you changing the objectMode variable? there’s nothing in the post code that changes it from false to true…

I do that in a function that 'listens for Tap (touch input) ← that works.
code:

function OnTap( gesture : TapGesture )
{
    //var a = GameObject("_GUI").GetComponent(modeControl);
    if(gesture.Selection.gameObject.tag == "notAnObject"){
    	Debug.Log( "ACTIVE " + gesture.Position + " on " + gesture.Selection.name );
    	objectMode = false;
    	modeControl.objectMode1 = false;
    	
    	
  
    	modeControl.objectName = gesture.Selection.name;
    	print(objectMode);
    	modeControl.activeObject = null;
    	
    }

That piece of code changes the objectMode to false. But what changes it to true?

Also, where do you assign materialWhenObjectActive to the renderer’s material?

I have an if statement looking for another Tag, just did not paste it.

Basically, how can you have a lot of objects with same scripts, but only change one of these objects from another script?
I cant do it by name since they are called the same. By tag is also unwanted since I might have 500 objects with the same script.

Well, they don’t have to be named the same. But if you don’t like to use name then implement your own “object id” functionality. I’ve done it a # of times and it works well. It will not let you search for a specific object if you have 100’s of them running around but it will let you distinguish between them if you got an instance of one of them through touch for example. You can even implement a generic “object pool” component. People do it for things like “bullet pool”, etc…

that sounds interesting, can you share some more of this?

Im thinking that when e.g. sphere(clone) is touched it will be assigned as a placeholder (var activeObject: gameObject) on another script.
You think that could be viable?