How to make two objects with the same directory source got different behaviours

Basically i’ll explain this with a example:

I have a Dot A and a Dot B in my scene.
Both of the dots are from the Dot prefab.

When i click in Dot A or Dot B the material rendering color change the color from Red to White.

The Question is: When i click whatever(Dot A or Dot B) the another Dot got the same event and do the same things, like a mirror, i want both with same script, but not sharing variables.

Any ideas?

Simply check the tag of the touchTaget object you are clicking on. For this example, create an empty scene with 2 cubes. Don’t worry about the material, the default diffuse will be fine. You will only be changing the color of an INSTANCE of the material, so each cube will have its own color, same material.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour 
{
	Ray ray;
	RaycastHit hit;
	Color color1 = Color.green;
	Color color2 = Color.red;
    GameObject touchTarget;
	
	void Update()
	{
		ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		if(Physics.Raycast(ray, out hit) && Input.GetMouseButtonDown(0))
		{
		    touchTarget = hit.collider.gameObject;
		
		    if(touchTarget != null)
			{
				if(touchTarget.tag == "DotA")
					hit.collider.renderer.material.color = color1;
				if(touchTarget.tag == "DotB")
					hit.collider.renderer.material.color = color2;
			}
		}
	}
}

EDIT: If you are going to have multiple “Dot” gameObjects, I would use an array. The only painful part of this would be assigning 20 different colors in the inspector, the rest is all in this small script. For this example, place 20 (Twenty) Cubes in your scene, just tag them “Dot”, all that same tag that we’ll use in the script. This code will grab all of your objects tagged “Dot” and put them in an array. Then it will assign the color depending on the index they hold in the array. Hope this makes sense, give it a shot.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour 
{
	Ray ray;
	RaycastHit hit;
	public Color[] colors = new Color[20];
	GameObject[] dots;
    GameObject touchTarget;
	
	void Awake()
	{
		dots = GameObject.FindGameObjectsWithTag ("Dot");	
	}
	
	void Update()
	{
		ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		if(Physics.Raycast(ray, out hit) && Input.GetMouseButtonDown(0))
		{
		    touchTarget = hit.collider.gameObject;
		
		    if(touchTarget != null)
			{
				if(touchTarget.tag == "Dot")
				{
					for(int i = 0; i < dots.Length; i++)
					{
						if(dots *== touchTarget)*

dots_.renderer.material.color = colors*;
}
}
}
}
}
}*_

It’s not about script behavior is being mirrored. Materials are global objects. If you change the color of a material, it’s gonna affect all the object that uses that material.

You should create two materials for two objects. Even if they are coming from same prefab, you can assign different materials in the scene objects.

It all depends what the logic is for clicking on your dots.
But if that is not the problem (and I guess it is not), just call renderer.material instead of renderer.sharedMaterial when you change the color of your material, and it will only affect that particular object’s material.

If the object’s material is used by other renderers, calling renderer.material will clone the material and always use that one instead, from that point on.