Bool Trigger Always = true problem

Basically what’s supposed to happen is the player can walk up to a door of a building in a town (where a collider is) and press ‘E’ to change to that scene. But instead of the player needing to be in the collision trigger, they can press e from anywhere and transition scenes. So I just assumed that “innTrigger” is automatically being assigned as true for some reason. I appreciate all the help!!! :slight_smile:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class SceneChange : MonoBehaviour {
   
    public Text pressE;
    public Collider Player;
    public string Scene;
    public bool innTrigger;

    void Start ()
    {
        pressE.text = "";
        innTrigger = false;
    }


    void OnTriggerEnter (Collider Player)
    {
        innTrigger = true;
        pressE.text = "Press 'E' to Enter";
    }

    void Update ()
    {
        if (innTrigger = true)
        {
            if (Input.GetKeyDown ("e"))
            {
                Application.LoadLevel (Scene);
            }
        }
    }

    void OnTriggerExit (Collider Player)
    {
        innTrigger = false;
        pressE.text = "";
    }
}

if (innTrigger = true) should be if (innTrigger == true)

3 Likes

Line 27.
You have “=” which assigns true. You need “==” which compares. It will always return true the way you have it now.

3 Likes

Im going to milk this even further.

Change line 27 to

if(innTrigger == true)

It is crucial to have TWO (2) equal signs!!!

1 Like

No no no, just use

if(innTrigger)
6 Likes

Thank you for the answers!

Just use the scripting forum next time. :roll_eyes:

At least he used code tags.

3 Likes