Script interaction

Due to hierarchy/inspector I feel like I’ve been digging for a very simple question for a very long time and yes, I am very new to unity.

I generally have a game object I attached other game objects to that hold multiple stats, and I want to add them together.

Hierarchy Example:
->All Stats (Body.Health+Legs.Health, Body.Armor+Legs.Armor) (script = Stats.cs)
->->Body (Health, Armor) (script = Body.cs)
->->Legs (Health, Armor) (script = Legs.cs)

I don’t want to make a static variable as I’m planning on having multiple players later and also, I want the health/armor to change later when you equip some different armor. I also am hoping to have “sets” you can save and switch between as you want and a shop to populate new body/leg armor when the scene loads so it would be nice to be able to script new instances on Start().

I see some tutorials say you have to have both be MonoBehaviors to share public variables, but I keep getting compilation errors when trying to do GameObject.Find or something.

Here is a simplified version of what I have so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bodyStats : MonoBehaviour
    public int Health = 32;
    public int Armor = 32;

How would I call bodyStats.Health or bodyStats.Armor variables in Stats.cs? Is this not setup properly and I have to change Body.cs to call such variables outside the script? Scriptable Objects also seem similar to what I am looking for, but also I can’t get those variables to pull into Stats.cs either.

You should make a public variable in your Stats.cs like this:

public bodyStats _bodyStats;

Then you will go to editor and assign link to this object. When link is assigned, you will be able to use your bodyStats.cs variables from the Stats.cs: