Accessing a bool from a different monobehaviour

I have a bool (isGrounded) from my player’s movement control script that I want to access in another GameObject.


public class BallController : MonoBehaviour {

Transform myTrans;
Rigidbody2D myBody;

public bool isGrounded = true;
public bool release = false;



public class GravityPull : MonoBehaviour {

public GameObject target;
public int moveSpeed;
public int maxdistance;
private float distance;

void Start ()
	target= (GameObject.Find("Ball (1)"));

void Update ()
	distance = Vector2.Distance (target.transform.position, transform.position);

	if (distance < maxdistance && target.isGrounded)
		target.transform.position = Vector2.MoveTowards(target.transform.position, transform.position, moveSpeed * Time.deltaTime / distance);

If I make my target a GameObject than I can find it using .find. But if I do this I can’t access the bool. If I make my target a BallController then I can access the bool, but I can’t use .find to find the class. I also can’t cast the GameObject as a BallController. Can someone tell me what I’m doing wrong here?

@jamesstephenbrown ,
Not sure if this is what you mean but I’m using a couple of different methods to access other scripts.
Hope it helps :slight_smile:

//Clock button
	public void  GoComLinkClock(){
	IEnumerator LoadT7(){
		yield return new WaitForSeconds(0.1f); // wait time
		CameraSwitcher cs2 = FindObjectOfType<CameraSwitcher>();


	public void  GoAnalyzer(){
		//Send to Sending script for message out to Arduino
		Sending.sendYellow2 ();

	IEnumerator Analyzer01(string analyzer){
		yield return new WaitForSeconds (0.5f); // wait time
		Application.LoadLevel (analyzer);

Your isGrounded variable is in a script/class called BallController, so you have to access it like so (assuming the BallController script is attached to the Target Object):