- Home /
Using my variables
Hi, so I have two scripts for the sake of readability. One controls the character movement: "Movement" C#, the other is going to control the rules attached to the character. So, if say the player drops to -20 on the y: transform.position = transform.position + new Vector3(0, 5, -10);
For my rules script I want to be able to use the variables created in my Movement script. I have done this:
[RequireComponent (typeof (Movement))] But no such luck.
So I was wondering just how I could potentially do this.
Referencing variables from script B in script A is a core part of Unity, and for that reason there are a bazillion tips, guides, tuts, former UA posts, etc on this topic; please take some time to review a tut/doc on GetComponent.
on script A (C#)
Script B scriptBvar = GetComponent<ScriptB>();
your syntax will change depending on various scenarios, but that's the basic form