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;
}