Project_WL/Assets/Script/Mgr/MobControlMgrList.cs

31 lines
940 B
C#
Raw Normal View History

2024-12-15 01:39:39 +00:00
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; // 가장 가까운 위치 반환
}
}