,How do i refrence a variable from one script in another script

,I know this is just basic code but I’m struggling

To reference a variable from one script in another script, you can use the “public” access modifier in the script where the variable is declared. This makes the variable accessible to other scripts in your project.

Here’s an example:

Script A:

public class ScriptA : MonoBehaviour
{
    public int myVariable;
}

Script B:

public class ScriptB : MonoBehaviour
{
    private ScriptA scriptA;

    void Start()
    {
        scriptA = FindObjectOfType<ScriptA>();
        int variableValue = scriptA.myVariable;
    }
}

Note that you’ll need to make sure that an instance of ScriptA exists in the scene at runtime, or else the FindObjectOfType function will return null and cause an error. You can ensure that an instance of ScriptA exists by attaching it to a game object in the scene.