How can i make GetComponent(SCRIPT) apply to ONLY ONE object that has the script?

Ive looked and looked. Tried and tried. I dont understand why this wont work.

Say you have 100 objects with the same script.

Each of those Objects has children.

If i mouse click on a child, i want that child to:

1:Identify its parent

2:Change a variable of the parent’s script

3.Then destroy itself

The problem is when i click on the child, it changes all 100 object’s variables that have the same script. I am using:

target = transform.parent.GetComponent(ParentScript);

target.BooleanVar = true;

target.IntegerVar = 1;

Thanks abunches! :slight_smile:

I can see two possible causes:

  1. Your variables at “ParentScript” are static, meaning that they belong to the class, not to the instance.
  2. You have an error in your click detection function and your script is changing it all.

Without your click detection and your ParentScript codes, it’s impossible to tell.