its been i while since ive used unity (or coded in general) and ive forgotten how to share a variable between 2 script. i have 2 scripts they both have a variable called underChunkX
my first script updates the variable frequently my second script need this variable, ive look up tutorials but nothing ive tried works, my second script with the variable returns 0
My first script (variables home):
public float underChunkX;
void OnCollisionEnter(Collision col){
underChunkX = col.gameObject.transform.position.x;
}
My second script(where i need the variable):
void Update(){
underChunkX = player.GetComponent<Player> ().underChunkX;
Debug.Log (underChunkX);
}
Note “player” is the gameobject that the “Player” class is attached to