Guest User

Untitled

a guest
Nov 6th, 2020
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. using Skatebirb;
  2. using UnityEngine;
  3.  
  4. namespace Skatebirb
  5. {
  6. public class GapGateZone : MonoBehaviour
  7. {
  8. protected virtual void AttemptToTriggerGap(Collider triggeringCollider)
  9. {
  10. if (triggeringCollider.attachedRigidbody == null || triggeringCollider.attachedRigidbody.gameObject == null) { return; }
  11.  
  12. ISkateboardGateway triggeringSkateboard = triggeringCollider.attachedRigidbody.gameObject.GetComponent<ISkateboardGateway>();
  13. if (triggeringSkateboard == null)
  14. {
  15. Gameplay.Skater triggeringSkater = triggeringCollider.attachedRigidbody.gameObject.GetComponent<Gameplay.Skater>();
  16. if (triggeringSkater != null) { triggeringSkateboard = triggeringSkater.OurSkateboard; }
  17. }
  18. if (triggeringSkateboard == null) { return; }
  19.  
  20. if (!IsGateTriggeredBy(triggeringSkateboard)) { return; }
  21.  
  22. // Generally, once a gate is triggered - that's it, we're done, poof!
  23. Managers.MissionManager.GapGatePassed(triggeringSkateboard, this);
  24. }
  25.  
  26. protected virtual bool IsGateTriggeredBy(ISkateboardGateway triggeringBoard)
  27. {
  28. return false;
  29. }
  30.  
  31. protected virtual void OnTriggerEnter(Collider other)
  32. {
  33. if (other == null || other.gameObject == null) { return; }
  34.  
  35. AttemptToTriggerGap(other);
  36. }
  37.  
  38. private void OnDrawGizmosSelected()
  39. {
  40. Color transparentColor = Color.grey;
  41. transparentColor.a = 0.5f;
  42. Gizmos.color = transparentColor;
  43.  
  44. BoxCollider ourBox = GetComponent<BoxCollider>();
  45. if (ourBox != null)
  46. {
  47. Gizmos.matrix = gameObject.transform.localToWorldMatrix;
  48. Gizmos.DrawCube(ourBox.center, ourBox.size);
  49. }
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment