boolean variables and small coding errors

advertisements

Basically I am making a variable in the game where when a player passes a collider it displays the message shown. However, I have a few errors if someone could help me with. I'm not sure exactly where I went wrong and its gotten pretty frustrating.

using UnityEngine;
using System.Collections;

public class showMessage : MonoBehaviour {
    GameObject player;
    private bool  startLap;

    void  OnTriggerEnter ( Collider other  ){
        if(other.tag == "Player") {
            bool = true;
        }
    }

    void  OnGUI (){
        if(bool == true) {
            if(GUI.Button ( new Rect(100, 100, 500, 40), "Help! I lost my car. Find it through this maze for me?")) {
                Debug.Log("Door Works!");
                bool = false;

            }
        }

    }
}

Ok fixed the bool bool just saw that :\

The errors I am getting are:

(10,30): error CS1525: Unexpected symbol =', expecting.', ?',[', <operator>', oridentifier'

(15,26): error CS1525: Unexpected symbol ==', expecting.' error CS1525: Unexpected symbol =', expecting.'

error CS8025: Parsing error


bool is a reserved keyword for boolean value data type - don't use it as field name, or you will get many compilation errors. Rename this field to something else.

Your code must look like this:

using UnityEngine;

public class showMessage : MonoBehaviour
{
    private bool startLap;

    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            startLap = true;
        }
    }

    void OnGUI()
    {
        if (startLap)
        {
            if (GUI.Button(new Rect(100, 100, 500, 40), "Help! I lost my car. Find it through this maze for me?"))
            {
                Debug.Log("Door Works!");
                startLap = false;
            }
        }
    }
}