GetComponent Public Float

Hi,

I have a public float in one of my scripts that I need in another one of my scripts, I have used GetComponent to reference the script where the public float is, I just don’t know how to get this script to see the float. Can anyone help?

Well if I understand correctly, here an example:

  1. attach each script to a gameobject in the hierachy
  2. then select the gameobject that has the scriptA
  3. and drag and drop it to the field in the scriptB (in the inspector)

Note: to do it: first select the scriptB, then click without releasing the scriptA (that way the scriptB will stay open on the inspector)

public class ScriptA : MonoBehaviour
    {
        public float myPublicFloat;
        
    }


public class ScriptB : MonoBehaviour
    {
        public ScriptA attachedScriptA;

        // Update is called once per frame
        void Update()
        {
            float damage = attachedScriptA.myPublicFloat * 9000;
            Debug.Log("Hit something with damage: " + damage);
        }
    }