Referencing a different script

Okay I did this about a year ago and I know that I have to use GameObject.Find(“…”) to find the script. but what I am trying to do, is I am trying to reference a script to check if the player has equipped a piece of armor and to see if that piece of armor is a specific type (Already done this part) But now I need to return a value on my Armor Equip script IF the armor in my inventory script was equipped.

I have my inventory setup so that if the player equipped a tunic, the Tunic Boolean var named “Equipped” would be returned as True in my Armor script. I just can’t remember what order they go in. Any clarification would be appreciated!

You can use the function GetComponent to get individual scripts and components from your objects.

Thanks for the fast reply! My question wasn’t very clear, What I was asking is what would a sample script look like to begin the reference?

without knowing how/what you’ve got setup in your code I’m not sure we can answer that :s

I just wrote this in the code inserter - but should pretty much work. For a Boolean you wont actually even need the == true part as it can evaluate it by default.

GameObject myObject;
myObject = GameObject.Find("CharacterGameObject");

myObject.GetComponent(<Armor>);

if(myObject.Armor.Equipped == True)
{INSERT CODE}

Well what I have setup is 2 Scripts that talk to each other. 1 Named “Item” which is my games items database. The other is “Inventory” that is connected to the player directly. Within the Inventory script I have it so if the player equips a tunic it puts it in EquipMenu[0] for array slot 0. But if it’s Equipped then it also changes my boolean, called “Equipped” to True. When that is finished, I have a third script that I want to check and see if that boolean is true, IF it’s true then I want it to change my material renderer for the chest to the armor. (that part I know how to do as well, I just can’t remember how to setup the GetComponent function from one script to the other)

Ahhhhh okay thanks a lot Darhkuan, that’s what i was looking for!

Thanks everyone else for the replies :slight_smile: