OnTriggerEnter For Parking
Hello everyone, i created 5 tigger cubes, one in the middle where i park car. 4 surrounded so i know when i parked my car. trying to guess it like if im in middle trigger and not in other triggers i have parked, something i tried didnot work
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class entertrigger : MonoBehaviour
{
public bool parked;
public bool tryingtopark;
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Parkingplace") {
parked = true;
}
if (other.tag == "NOTparkingplace")
{
tryingtopark = true;
}
}
public void OnTriggerExit(Collider other)
{
if(other.tag == "NOTparkingplace")
{
tryingtopark = false;
}
}
public void parkingstatus()
{
if (parked == true && tryingtopark == false)
{
Debug.Log("You are parking master");
}
}
}
Answer by rstrong · May 04, 2020 at 03:59 AM
(edit) Sorry I wasn't thinking clearly when I answered the first few times lol. It looks like you just need to call your parkingstatus() method here:
if(other.tag == "Parkingplace"){ parked = true; parkingstatus(); }
Then in the OnTriggerExit add the following if statement:
if(other.tag == "Parkingplace") { parked = false; }
Then in the OnTriggerExit for NOTparkingplace call your parkingstatus method again:
if(other.tag == "NOTparkingplace") { tryingtopark = false; parkingstatus(); }
Your answer
Follow this Question
Related Questions
OnTriggerExit2D doesn't work when one of gameObject setActive false. 0 Answers
How do I differentiate between the triggers? 1 Answer
OnTriggerEnter is not called 1 Answer
C# OnTriggerEnter Issue 3 Answers
Text disappear on OnTriggerExit() 1 Answer