.4453125using UnityEngine;
using System.Collections;
public class Ex6_4 : MonoBehaviour {
// Use this for initialization
void Start () {
int index = -1;
int[] npc_hp = new int[5]{10, 20, 30, 40, 50} ;
FindMax(npc_hp, ref index);
print("Max Value = " + npc_hp[index] + ",index = " + index);
}
static void FindMax(int[] npc_hp, ref int index){
//npc_hp = new int[5]; 초기화 하는법.
int max = int.MinValue;
index = -1;
for(int i = 0; i < npc_hp.Length; i++)
{
print ("max" + npc_hp[i]);
if( max < npc_hp[i]){
max = npc_hp[i];
index = i;
}
}
print (max);
}
// Update is called once per frame
void Update () {
}
}
'Computer Language > 유니티' 카테고리의 다른 글
out 결과값을 받을때 씀 (0) | 2014.04.22 |
---|---|
swap 배열 사용시 기초 예제 (0) | 2014.04.22 |
오버로딩. (0) | 2014.04.21 |
goto문 2중 for문에서 합의하에 사용가능 (0) | 2014.04.21 |
학생들 성적의 합과 평균 그리고 이름 찍기 (0) | 2014.04.21 |