# Is it possible to get another public variable from another script?

I am making it so that if you click a box, it teleports over an object and that objcet detects the collision. The characters dialog script is inside of a character I made. I also have a boolean value that is inside of a script that is inside the object that detects the collision. I want to make it so that if it detects collision the dialog changes for the character. Is there any way that I can reference the variable inside of the script? Also, here are some blurbs from the scripts:

//This is the object where you click it to make it teleport
if (gameObject == box)
{
Debug.Log("TEST");
box.transform.position = new Vector3(tploc.transform.position.x, tploc.transform.position.y, tploc.transform.position.z);
}
//The on variable represents if the box is touching the collision detector, but it has no meaning at the moment
if (on == 0)
{
if (gameObject == mel)
{
panel3.SetActive(true);
}
}


This script uses RayCasting to detect clicks on the object

The next script detects the collision:

using System.Collections;


using System.Collections.Generic; using UnityEngine;

public class scannercollider : MonoBehaviour { public GameObject box; public GameObject sound; public bool iscolliding; // Start is called before the first frame update void Start() {

}
private void OnCollisionEnter(Collision collision)
{
if (collision == null)
{

}
if (collision.gameObject == box)
{
iscolliding = true;
Debug.Log("the box is on the scanner at the moment");
sound.GetComponent<AudioSource>().Play();
}
}
// Update is called once per frame
void Update()
{


} }

• It is not really clear what is what, but you can access the public variable without problem when you know where it is. Use theOtherGameObject.GetComponent<YourOtherScript>().yourVariable similar what you did with sound, just that Play() is a method there. Dec 29 '21 at 17:49