How do you instantiate a class in C#

Hi, I have got these two scripts, one is supposed to access the other classes’ health, but first I need an object reference, how do you do that?

using UnityEngine;
using System.Collections;

public class PlayerClass : MonoBehaviour {
	
	public int Health = 100;

	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
using UnityEngine;
using System.Collections;

public class HealthGUI : MonoBehaviour {

	// Use this for initialization
	void Start () {
		Debug.Log (PlayerClass.Health);
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

There are different possibilities to do that. One is:

Place a reference to your Player game object in your HealthGUI script and fill it with the Inspector in Unity with the GameObject which has attached your PlayerClass script. Change your HealthGUI script to the following:

    using UnityEngine;
    using System.Collections;
     
    public class HealthGUI : MonoBehaviour {

        public GameObject PlayerObject;
        private PlayerClass player;
     
        // Use this for initialization
        void Start () {
            if (PlayerObject != null)
            {
                 player = PlayerObject.GetComponent<PlayerClass>();
                 if (player != null)
                 {
                       Debug.Log (player .Health);
                 }
            }
            
        }
       
        // Update is called once per frame
        void Update () {
       
        }
    }

Are they on the same object? If so, use GetComponent(); to get a reference.
If they are on different objects, you can create a reference for the object and drag it onto it in the editor and then use getcomponent. Or you can tag it, and use FindGameObjectWithTag(); or just Find, in the start Menu.

scriptName script;
void Start(){
script = GetComponent();
}

Typically, I would do something along the lines of…

public GameObject PlayerObject;



void MakeObjectClone()
{
GameObject clone;

clone = Instantiate(PlayerObject, position, rotation);
}

At a bare minimum, all you need is to declare the object and attach the prefab you want,
Create a clone, and then make that clone instantiate into whatever the prefab object is.

From here, you can do all kinds of nifty things…

For instance, if you were to create a Rigid Body…

public rigidBody Object;
public float speedAtStart;



void MakeObjectClone()
{
GameObject clone;


clone = Instantiate(Object, position, rotation) as rigidBody;
clone.AddForce(speedAtStart)
}

My codes a little sloppy, but this is how one would make a moving object spawn, or fire a bullet/projectile.

in your case, though it will be much easier to just make you Health variable public static. Then you can access it directly without the need to instantiate the class.