diff options
Diffstat (limited to 'JamHelper/Assets/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/WallChecker.cs')
-rw-r--r-- | JamHelper/Assets/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/WallChecker.cs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/JamHelper/Assets/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/WallChecker.cs b/JamHelper/Assets/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/WallChecker.cs new file mode 100644 index 0000000..a437113 --- /dev/null +++ b/JamHelper/Assets/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/WallChecker.cs @@ -0,0 +1,74 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace JamUtils +{ + + + public class WallChecker : MonoBehaviour + { + + private bool m_IsOnWall; + public bool IsOnWall + { + get + { + return m_IsOnWall; + } + } + + private List<Collider> m_Colliders = new List<Collider>(); + + private void Update() + { + if (m_IsOnWall && m_Colliders.Count == 0) + { + m_IsOnWall = false; + } + } + + public bool GetCollisionPoint(out Vector3 point) + { + bool result = false; + point = Vector3.zero; + if (m_Colliders.Count > 0) + { + float dist = 100f; + for (int i = 0; i < m_Colliders.Count; ++i) + { + Collider col = m_Colliders[i]; + Vector3 p = ColliderUtility.FindClosestPoint(col, transform.position); + if (Vector3.Distance(p, transform.position) <= dist) + { + dist = Vector3.Distance(p, transform.position); + point = p; + result = true; + } + } + } + return result; + } + + private void OnTriggerEnter(Collider other) + { + m_IsOnWall = true; + + m_Colliders.Add(other); + } + + private void OnTriggerStay(Collider other) + { + } + + private void OnTriggerExit(Collider other) + { + if (m_Colliders.Contains(other)) + { + m_Colliders.Remove(other); + } + } + + } + +} |