reference to script not working

I'm trying to call Test(); from a script called addnumbers in a gameobject called master. When I drag master that has addnumbers.js attached to the slot for ScriptB in test.js Editor won't accept it. test.js is attached to instantiated prefab objects. I tested this method on other object that are not instantiated prefabs and it works, but not on instances. Is there a solution? Sure there is, there always is...:)

//test.js script
var ScriptB : addnumbers;

function Update () {
   ScriptB.Test();

//addnumbers.js script
function Test() {

    print("It works!     ========");
}
}

Not that it matters but normally variables start with lower case letters and scripts and classes etc. start with upper case letters

1 Answer

1

c# :

 GameObject obj;
 Addnumbers ScriptB;
 void Start(){
    obj = GameObject.Find ("master");
    if (obj != null) {
      ScriptB= obj.GetComponent<Addnumbers> ();
    }
  }
    void Update(){
    ScriptB.Test();
    }