The easier solution will be creating two colliders. the first collider sense the player and tell the second collider the direction is sensed.
the first collider code:
using UnityEngine; using System.Collections; public class mistake4Collider : MonoBehaviour { public static bool collidedA; void OnTriggerEnter(Collider other){ if (other.gameObject.CompareTag ("Player")) { collidedA = true; } else { collidedA = false; } } }
for second collider
using UnityEngine; using System.Collections; public class mistake4BCollider : MonoBehaviour { bool ToggleGUI = false; bool isCreated = false; GameObject msg; void OnTriggerEnter(Collider other){ if (other.gameObject.CompareTag ("Player")) { if (mistake4Collider.collidedA == true){ ToggleGUI = true; playerLives.lives -= 1; } } } void OnGUI(){ if (ToggleGUI == true) { if(!isCreated){ GameObject msg = (GameObject)Instantiate(Resources.Load("GUI/Mistake4")); isCreated = true; } } } }