PresetTrigger.cs 1012 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace TrafficSimulation{
  5. public class PresetTrigger : MonoBehaviour
  6. {
  7. public bool isTriggered;
  8. public string triggerTag;
  9. private GameObject lastCollider;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. this.isTriggered = false;
  14. }
  15. // Update is called once per frame
  16. void Update()
  17. {
  18. }
  19. private void OnTriggerEnter(Collider other) {
  20. if(other.gameObject.tag == this.triggerTag){
  21. this.isTriggered = true;
  22. this.lastCollider = other.gameObject;
  23. }
  24. }
  25. public GameObject getLastCollider(){
  26. return this.lastCollider;
  27. }
  28. public bool checkLastTrigger(){
  29. bool currentState = this.isTriggered;
  30. this.isTriggered = false;
  31. return currentState;
  32. }
  33. }
  34. }