Change a Variable with another script not working (C#)

I am trying to change a boolean variable that is in ScriptA with ScriptB. Here is a small example:

public class ScriptA : MonoBehaviour {
  public bool followBall;

  void Update() {
     if(followBall)
         Make camera follow ball;
  }
}

public class ScriptB : MonoBehaviour {

public ScriptA a;

  void Update() {
     if(space is pressed) {
           create object to follow;
           a.followBall = true;
      }
  }
}

When I try to change the boolean variable in scriptA with scriptB it stays false. I made sure that I dragged the ScriptA component onto ScriptB. I don’t know what I am doing wrong?

You are doing that correctly - are you sure you are checking the right ScriptA when you see that it is still false? Are you sure the code here is executing?

public GameObject MyGameObject;
YourScript myScript;
void Start()
{
myScript = MyGameObject.GetComponent();
}
void Update()
{
//for example See is a bool in the script YourScriptName
if(myScript.See==true)
{
// do Something
}
}

How do you change the var in the js from the c# script?

Hi,

@Snownebula

Follow the link: Unity3D: JavaScript -> C# or C# -> JavaScript access | 41 Post