system
1
so i have two scripts and I want one of the scripts to use a variable on the other script and change it to true.
I have a dialogue system and i have a quest system. I want to be able to press okay and then change the a variable to true on the quest system.
ex : go kill the bat [ you press okay]
(the quest script sees if it has been accepted )
Please help
Waz
2
The two basic choices you have are:
-
Class variables - only appropriate of only one Quest script ever in your world
// Quest.js
static var okay = false;
// Dialogue.js
if (...) Quest.okay = true;
-
Reference between script components:
// Quest.js
var okay = false;
// Dialog.js
var questSystem : Quest;
if (....) questSystem.ok = true;
You then need to ensure `questSystem is set, either in the inspector or by looking it up in the Dialogue Awake function.
In the quest script have the variable as “public static bool okay = false;” without the quotes.
Inside of your dialog script put “if(Gui.Button…) questSystem.okay = true;” also without the quotes.
It is this way for both UnityScript and C#, the only difference is in C# one must explicitly state PUBLIC as variables are private by default, whereas in UnityScript they are public by default.