Hey there im new to unity so please forgive anything i say thats wrong.
Right now im trying to set up a Key script,
with a cube mesh, and clicked istrigger
I have made a new C# script, I would like to make a public boolean variable,
so if the player collides with the key trigger, the boolean variable changes and a door object opens up somewhere else in the level
does this all seem fine so far?
using UnityEngine;
using System.Collections;
public class Key : MonoBehaviour {
public boolean Key1Trigger = false;
// Use this for initialization
void Start () {
gameObject.renderer.material.color = Color.red;
}
// Update is called once per frame
void Update () {
Well, you have to get a reference to that script through Unity.
So, in Script2 you could do:
Public Script1 otherScript;
Then in the editor, drag the GameObject that has a Script1 component from the scene hierarchy onto the little rectangle in the inspector and that will build the reference for you.
There’s other ways to do it, as well. Then inside of Script2, to check Script1’s bool:
this, but don’t call ur boolean ‘bool’.
Since that’s already the type that you’re declaring it.
to avoid confusion, call it myBoolean. Or a more descriptive name that indicates what the on-off state means.