diff options
author | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
commit | 6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch) | |
tree | 7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/Walls/XTrigger.cs |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/Walls/XTrigger.cs')
-rw-r--r-- | Client/Assets/Scripts/Walls/XTrigger.cs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/Walls/XTrigger.cs b/Client/Assets/Scripts/Walls/XTrigger.cs new file mode 100644 index 00000000..cea27e25 --- /dev/null +++ b/Client/Assets/Scripts/Walls/XTrigger.cs @@ -0,0 +1,42 @@ +using UnityEngine;
+using XUtliPoolLib;
+
+public abstract class XTrigger : MonoBehaviour
+{
+ protected IXPlayerAction _interface;
+ private CapsuleCollider _cap = null;
+
+ // Use this for initialization
+ void Awake()
+ {
+ _cap = GetComponent<CapsuleCollider>();
+ _cap.enabled = false;
+ }
+
+ void Update()
+ {
+ if (_interface == null || _interface.Deprecated) _interface = XInterfaceMgr.singleton.GetInterface<IXPlayerAction>(1);
+
+ if (_interface != null && _interface.IsValid)
+ {
+ Vector3 pos = _interface.PlayerPosition(true);
+ Vector3 last_pos = _interface.PlayerLastPosition(true);
+
+ if ((last_pos - pos).sqrMagnitude > 0)
+ {
+ CollisionDetected(pos);
+ }
+ }
+ }
+
+ private void CollisionDetected(Vector3 pos)
+ {
+ Vector3 delta = (pos - (_cap.transform.position + _cap.center)); delta.y = 0;
+ if (delta.sqrMagnitude < _cap.radius * _cap.radius)
+ {
+ OnTriggered();
+ }
+ }
+
+ protected abstract void OnTriggered();
+}
|