Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NewBehaviourScript : MonoBehaviour
- {
- // Drop all your crouch points in here, from Inspector.
- public List<Transform> crouchPoints = new List<Transform> ( );
- public int CurrentCrouchPoint { get; set; } = -1;
- private Transform FindClosestCrouchPoint ()
- {
- var closestDistance = float.MaxValue;
- Vector3 origin;
- if ( CurrentCrouchPoint == -1 )
- origin = this.transform.localPosition;
- else
- origin = crouchPoints [ CurrentCrouchPoint ].localPosition;
- var closestCrouchPoint = CurrentCrouchPoint;
- for (int i = 0; i < crouchPoints.Count; i++ )
- {
- if ( i == CurrentCrouchPoint ) continue;
- var tempDistance = Vector3.Distance ( origin, crouchPoints [ i ].localPosition );
- if ( tempDistance < closestDistance )
- {
- closestDistance = tempDistance;
- closestCrouchPoint = i;
- }
- }
- CurrentCrouchPoint = closestCrouchPoint;
- return crouchPoints [ CurrentCrouchPoint ];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment