Then wherever you need it you call GetBoolValue(ID); and replace ID with the number of the Global Variable you want to use for it (the ID of each variable can be found in the Variables Manager of AC).
Chris said he was going to make this code a little easier in the next update.
AC's bools share the same value field as ints: 0=false, 1=true. There is a function that already does this for you, but returns a generic string, so try this instead:
Comments
{
foreach (GVar _var in GameObject.FindWithTag (Tags.persistentEngine).GetComponent <RuntimeVariables>().localVars)
{
if (_var.id == ID)
{
return _var.val;
}
}
return false;
}
public class AlarmOn : MonoBehaviour {
bool RoomLock;
public Transform light;
// bool light = true;
// Use this for initialization
void Start () {
bool GetBoolValue (int ID);
{
foreach (GVar _var in GameObject.FindWithTag (Tags.persistentEngine).GetComponent <RuntimeVariables>().localVars)
{
if (_var.id == ID)
{
return _var.val;
}
}
return false;
}
}
// Update is called once per frame
void Update () {
RoomLock = GetBoolValue (2);
if (RoomLock = false) {
light.enabled = !light.enabled;
}
else {
light.enabled = light.enabled;
light.intensity=0.5;
}
}
}
I get error CS1525: Unexpected symbol `(', expecting `)', `,', `;', `[', or `='
if (GameObject.FindWithTag (Tags.persistentEngine).GetComponent <RuntimeVariables>().GetVarValue (2)) == "1")
{
// TRUE
}
else
{
// FALSE
}
A more extensive tutorial is here.
Engine.GameObject.GetComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly
GameObject.FindWithTag (Tags.persistentEngine).GetComponent ().GetVarValue (2);