I have 2 scripts attached to a cube I’m trying to get variables from the other script,but it always comes up null. in the start function of the script , physics, I have
void Start () {
script = transform.parent.GetComponent<Movement>();
}
The MonoScript editor suggests Class Movement , but when I run it I get a null reference exception. Then I can not use any of Movement’s variables.
oops forgot to mention that this was in C#.
twisted’s suggestion let’s me access the variables in the editor, but when I actually run Unity it still throws an error.
Thanks thought I had use parent , when I didn’t.
This worked
Movement script;
// Use this for initialization
void Start () {
script = GetComponent<Movement>() as Movement;
}