29 lines
778 B
C#
29 lines
778 B
C#
using UnityEngine;
|
|
|
|
public class AmmoCrate : MonoBehaviour
|
|
{
|
|
// Ìîæíî äîáàâèòü ìàññèâ òî÷åê ïîäõîäà äëÿ ïèðàòîâ
|
|
public Transform[] approachPoints;
|
|
|
|
public Transform GetNearestFreePosition(Vector3 fromPosition)
|
|
{
|
|
if (approachPoints == null || approachPoints.Length == 0)
|
|
return transform;
|
|
|
|
Transform nearest = approachPoints[0];
|
|
float minDist = Vector3.Distance(fromPosition, nearest.position);
|
|
|
|
for (int i = 1; i < approachPoints.Length; i++)
|
|
{
|
|
float dist = Vector3.Distance(fromPosition, approachPoints[i].position);
|
|
if (dist < minDist)
|
|
{
|
|
minDist = dist;
|
|
nearest = approachPoints[i];
|
|
}
|
|
}
|
|
|
|
return nearest;
|
|
}
|
|
}
|