HOW TP GET VARIBALE FROM ANOTHER SCRIPT IN UNITY C++ code example

Example 1: get variable from other scriptin unity c#

//-------------------------------PUT IN ScriptA-----------
public ScriptB = scriptB;

void Start()
{
  scriptB.myFloat = 3.542f;
}
//---------------------------------------------
//---------------------------PUT IN ScriptB---------
//make sure public so it can be accessed from other scripts.
public float myFloat;
//script a will change myFloat to 3.542 from null;
//note this is for Unity and C#

Example 2: unity how to use variable from another script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Miner : MonoBehaviour // A class made to mine coins
{
	private Variables variables; // "Variables" is the class name with my variables in it, "variables" is the name of it's variable in this class

	void Start()
	{
		variables = GameObject.Find("ScriptHolder").GetComponent<Variables>(); // "ScriptHolder" is the name of the GameObject that holds the Variables class
	}

	public void Mine()
	{
		variables.coins += variables.minePower; // This is how you reference your variables
	}
}