RunTime instantiated clones are sharing a transform link?

Code instantiating the clones:

private void OnMouseUp()
	{
		clicked = Vector3.zero;
		transform.position = origin;
		Collider2D[] hit = Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition));
		foreach (Collider2D c in hit)
		{
			if (c.tag.Equals(dropTag))
			{
				active = false;
				GetComponent<SpriteRenderer>().color = Color.grey;
				turret = Instantiate(TurretType, c.transform).GetComponent<TurretBase>();
				turret.icon = gameObject;
			}
		}
	}

Code rotating the instantiated prefab:

private void FixedUpdate()
	{
		if (Input.GetMouseButtonDown(1))
		{
			transform.Rotate(Vector3.forward, 90);
		}
	}

the transform link itself doesn’t seem to be the same for every clone but right clicking any of them rotates all of them by 90 degrees.
any idea how i can get the script to only affect the specific object it is attached to?

if your Input.GetMouseButton is in the script of TurretBase, then anything containing the TurretBase script will rotate. Your code needs to be more defined(more checks/ifs) to specifically only happen when said turret isSelected.

Your Inputs should only be read once, and applied to a static value(means always exists in every script, and can be accessed from anywhere). I personally make a static Global class, which houses all the ints, floats, bools, and in some cases functions I wish to imply. So only a call of something like this, is what my code would look like:

// in turret class

Update()
{
    if (isSelected && Global.leftMouseButtonPressed)
    {
         // do particular logic
     }
}

And for setting the Global variables, I normally have a Master.cs which is the main script that always runs, and therefor gets the Inputs and sets the Global variables. Among doing other things, but mainly is what some call a GameManager.cs or GameController.cs.

Static variables and functions, will save your but* time and time again. Research and experiment with them, you will thank me later :slight_smile: