c# accessing variables from another script

Hi all, I have searched through the reference and I think I’m close, but I have no Javascript experiance and there was no c# example. I think I have some syntax errors here, but again, not sure.

public class HUD : MonoBehaviour {

	private int health;
	private int shield;
	private int missiles;
	private GameObject player;
	
	// Use this for initialization
	void Start () 
	{
		player = GameObject.Find("1-Middleground/Player");
	}
	
	// Update is called once per frame
	void Update () 
	{	
		GameObject script = player.GetComponent(Player_Attribs);
		health = script.health;

I get these errors:
CS0119: Expression denotes a type
CS1502 Best overload match is UnityEngine.GameObject.GetComponent(System.Type)
CS 1503 Argument #1 can not convert object expression to type system.type
CS1061 Type UnityEngine.GameObject does not contain a definition for ‘health’; and no …

It should probably be

Player_Attribs script = player.GetComponent(typeof(Player_Attribs));

or

Player_Attribs script = player.GetComponent<Player_Attribs>();

But this only works if Player_Attribs inherits from MonoBehaviour.

The second one is the only one I tried but it worked :slight_smile: Thanks so much!