I’m new to scripting and whilst I’ve muddled through using this forum, google and Youtube so far, I’ve hit a bit of a brick wall.
I’m trying to figure out how to get a script on one game object to change a property on another game object.
For example, I have MasterObject with the script attached to it. I then also have OtherObject01, OtherObject02 and OtherObject03.
When an integer variable in the script on MasterObject reads 1 (for example), I want it to tell the renderer in OtherObject02 and OtherObject03 to turn off - ie, set it to false but I cannot figure out how to specify those objects.
Initially I added a script to the OtherObjects that listened for the variable value and turned themselves off if the correct condition was met, but if I have dozens or hundreds of these OtherObjects, that means dozens or hundreds of three-line scripts which seems horribly inefficient.
Equally, I have encountered the GetComponent command but as yet have been unable to get it to refer to a specific game object.
I did manage to get this to work:
public var OtherObject01: GameObject;
function Update() {
if(Setup.department == 1) {
OtherObject01.GetComponent.<Renderer>().enabled = true;
}
else {
OtherObject01.GetComponent.<Renderer>().enabled = false;
}
But this sets up public variables and I have to manually assign the game objects to those variables in the inspector. It must be possible to assign those game objects within the script or just name them directly. I just can’t figure out how.
Any help would be much appreciated.