On trigger show text
Hello, I'm making an indie horror game and i used this code to make the text appear when a player enters the collider and disappears when the player leaves it. it worked at first but as i progressed with making the game is stopped working, now the text shows up when i enter the collider but doesn't disappear when I leave it. Any help would be appreciated! here's my code.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Textlol : MonoBehaviour {
 public string text;
  bool display = false;
 // Use this for initialization
 void Start () {
     
 }
 // Update is called once per frame
 void Update() { }
 void OnTriggerEnter(Collider iCollide)
 {
    
 
     if (iCollide.transform.name == "Player")
     {
         display = true;
     }
 }
  void OnTriggerExit(Collider uCollide)
 {
     if (uCollide.transform.name == "player")
     {
         display = false;
     }
     if (display == false)
     {
         Destroy(gameObject);
     }
 }
  void OnGUI()
 {
     if (display ==true)
     {
         GUI.Box(new Rect(0, Screen.height / 1.21f, Screen.width / 1f, Screen.height / 19.58f), text);
     }
     else
     {
         Destroy(gameObject);
     }
 }
 
               }
Answer by jandd661 · Jul 27, 2017 at 02:15 AM
The first thing I saw was line 16 and 27. "Player" and "player". Debug.Log ("Player" == "player"); returns false
Your answer
 
             Follow this Question
Related Questions
Trigger FinishLine 1 Answer
How i make one trigger work if there only one object in it ? 0 Answers
How to detect collision of two moving characters? 1 Answer
AI and Enemy Detection 1 Answer
Change Scene with Physics Raycasting 1 Answer