I want to set the variable “target” equal to the value of the variable “targetA” in another script. I thought I could do it using the following script, but it’s not working. Any ideas?
var linkToOrcIdentifierCode : OrcIdentifierCode;
function SetTargetAO ()
{
target = linkToOrcIdentifierCode.targetA;
}
You haven’t set that “linkToOrcIdentifierCode” to anything. You’ve just declared it.
Presumably in your Start function, you’re going to want to do linkToOrcIdentifierCode = GameObject.Find(“NAME_OF_OBJECT_SCRIPT_IS_ON”).getComponent(OrcIdentifierCode);
Or however it is that you want to access the gameObject that has the script on it. Your call.
I solved this problem another way. Rather than trying to access the variable through a link to the other script, I just declared the variable I wanted to access in the other script “static”. [Here][1] is where I found a very clear and easy to follow explanation of the code.
Here’s the adjusted code. In the other, accessed script,
static var target A : GameObject;
And in the accessing script,
function SetTargetAO ()
{
target = OrcIdentifierCode.targetA;
}
Notice that I no longer needed to create a variable linking to the other code. Because I had declared the variable I wanted to access “static”, I could just call it using the dot matrix system. In the link above is a more thorough and very lucid explanation of the dot matrix system as it applies to static variables.