31 lines
940 B
C#
31 lines
940 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class MobControlMgrList : MonoBehaviourSingletonTemplate<MobControlMgrList>
|
|
{
|
|
List<Vector3> list = new List<Vector3>();
|
|
|
|
public void Add(Vector3 pos) { list.Add(pos); }
|
|
public Vector3 Get_NearstMobGen(Vector3 pos)
|
|
{
|
|
//if (list.Count == 0)
|
|
//return Vector3.zero; // 리스트가 비어있으면 기본값 반환
|
|
|
|
Vector3 nearestPos = list[0]; // 첫 번째 위치를 기본값으로 설정
|
|
float nearestDistance = Vector3.Distance(pos, nearestPos);
|
|
|
|
foreach (var mobGenPos in list)
|
|
{
|
|
float distance = Vector3.Distance(pos, mobGenPos);
|
|
|
|
if (distance < nearestDistance)
|
|
{
|
|
nearestDistance = distance;
|
|
nearestPos = mobGenPos;
|
|
}
|
|
}
|
|
|
|
return nearestPos; // 가장 가까운 위치 반환
|
|
}
|
|
} |