Assigning variables of a script, from another script

So I have a relatively simple problem which I have spent way too much time on, because I cannot seem to find a way around it.

Simply put, I would like to change a value of a script variable inside a specific object, using another script.

I have 2 objects I would like to attack each other, but only each other. I would like the surrounding allies/enemies to ignore these 2 objects while they “duel” each other. My approach was to simply have an “inCombat” boolean, and have the targeting function ignore objects that were considered “inCombat”.

This meant when an object acquired a target it would set both their “inCombat” variables to true, and force them to taget each other. However, I dont have a way to set the other object “inCombat” varabile to true, which is located in a script governing the movement of that object.

what I would like to do is roughly this.

myTarget = other.gameObject.transform;
myTarget.inCombat = true;
inCombat = true;

anyone know a way around this?
is there a gameObject.SetComponent(inCombat) = true; I dont know about?

I tried working around it using messages, which did not work. I will try again with those as I think a forced update might help it.

myTarget.gameObject.SendMessage("SetTarget",gameObject.transform,SendMessageOptions.DontRequireReceiver);
    			myTarget.gameObject.SendMessage("SetCombat",true,SendMessageOptions.DontRequireReceiver);
    
    function SetTarget(target : Transform)
    {
    	myTarget = target;
    }
    function SetCombat(combat : boolean)
    {
    	inCombat = true;
    }

Here you go

You can use functions same way.

So I ended up linking that script to my current script using GetComponent. I tried this in the past without any luck, and figured that I could only assign a variable to the value of a variable within the other script, and not directly alter the other scripts variables.

However, I had a lot of junk floating around that was probably causing issues with this from correctly working. After re-implementing this function on a smaller scale I was able to debug it and see that it was in fact assigning values to the script variables of that objects target.

here is a snippet from what I am currently using

var targetCheck : EnemyOrbitting = other.gameObject.GetComponent(EnemyOrbitting);
targetCheck.inCombat = true;
targetCheck.myTarget = this.transform;

this seems to be correctly altering the variables inside the object with the (“EnemyOrbitting”) script attached, even with multiple instances of that object within its collision radius.