.4453125using UnityEngine;
using System.Collections;
public class ddd : MonoBehaviour {
void Start () {
int npcindex, distance;
if(FindNpc(30, out npcindex, out distance)){
print ("find ok, index = " + npcindex);
}
else{
print ("Find Fail");
}
}
bool FindNpc(int range, out int index, out int minDistance){
int[] npc = {30, 40, 50, 20, 60} ;
index = -1;
minDistance = int.MaxValue;
for(int i = 0; i <npc.Length; i++){
if(npc[i] < range && npc[i] < minDistance){
index = i;
minDistance = npc[i];
}
}
return (index != -1) ? true : false;
}
// Update is called once per frame
void Update () {
}
}
'Computer Language > 유니티' 카테고리의 다른 글
params 가변인자 (0) | 2014.04.22 |
---|---|
params 매개변수 제한이 없다. (0) | 2014.04.22 |
swap 배열 사용시 기초 예제 (0) | 2014.04.22 |
최대값 (0) | 2014.04.22 |
오버로딩. (0) | 2014.04.21 |