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?
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:
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);
}
}