void Start () {

print (Sum (1, 2,3,4,54,5,5,6,6));

}

int Sum(params int[] args){

int sum = 0;

for(int i = 0; i < args.Length ; i++){

sum += args[i];

}

return sum;

}


'Computer Language > 유니티' 카테고리의 다른 글

params  (0) 2014.04.22
params 가변인자  (0) 2014.04.22
out 결과값을 받을때 씀  (0) 2014.04.22
swap 배열 사용시 기초 예제  (0) 2014.04.22
최대값  (0) 2014.04.22

.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

.4453125void Start () {

int a = 0, b = 0, c = 0;

Swap (ref a, ref b);

print (a + " " + b);

int[] score = new int[3]{40, 30, 20} ;

if(score[1] < score[0])

ArraySwap(ref score[0], ref score[1]);

if(score[2] < score[1])

ArraySwap(ref score[1], ref score[2]);

if(score[2] < score[0])

ArraySwap(ref score[0], ref score[2]);

if(score[1] < score[0])

ArraySwap(ref score[0], ref score[1]);

for(int i = 0; i < 3; i++)

print (score[0] + " " + score[1] + " " + score[2]);

}

void Swap(ref int a, ref int b){

int temp = a;

a = b;

b = temp;

}

void ArraySwap(ref int a, ref int b){

int temp = a;

a = b;

b = temp;

}


'Computer Language > 유니티' 카테고리의 다른 글

params 매개변수 제한이 없다.  (0) 2014.04.22
out 결과값을 받을때 씀  (0) 2014.04.22
최대값  (0) 2014.04.22
오버로딩.  (0) 2014.04.21
goto문 2중 for문에서 합의하에 사용가능  (0) 2014.04.21

.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 () {

}

}




using UnityEngine;

using System.Collections;

class Calc8{

static public int Plus(int a, int b){

return a + b;

}

static public double Plus(double a, double b){

return a + b;

}

}



public class Chapter7 : MonoBehaviour {


// Use this for initialization

void Start () {

int a = 34, b = 10;

print(Calc8.Plus(a, b));

double c = 3.4f, d = 5.6f;

print(Calc8.Plus(c, d));

}

// Update is called once per frame

void Update () {

}

}



using UnityEngine;

using System.Collections;


public class Chapter5 : MonoBehaviour {


// Use this for initialization

void Start () {

int i = 0, j = 0, count = 0;

for(i = 0; i < 5; i++){

for(j = 0; j < 5; j++){

count += 1;

if(count > 20)

goto EXIT_FOR;

}

}

print ("end of for");

EXIT_FOR:

print (count +", i =" + i + ", j=" + j);

}

// Update is called once per frame

void Update () {

}

}



'Computer Language > 유니티' 카테고리의 다른 글

최대값  (0) 2014.04.22
오버로딩.  (0) 2014.04.21
학생들 성적의 합과 평균 그리고 이름 찍기  (0) 2014.04.21
String.Format 잘 봐두자 유용하게 쓰인다.  (0) 2014.04.21
포맷 형식  (0) 2014.04.21


using UnityEngine;

using System.Collections;


class Student {

public string Name;

public int[] Score = new int[3];

public Student(string name, int Score1, int Score2, int Score3){

Name = name;

Score[0] = Score1;

Score[1] = Score2;

Score[2] = Score3;

}

public int Total(){

return Score[0] + Score[1] + Score[2];

}

public int Avg(){

return Total () / 3;

}

public void ShowPrint(){

Debug.Log("Name=" +Name + " Total =" + Total() + " Avg=" + Avg()); 

}

}


public class hamStu : MonoBehaviour {


// Use this for initialization

void Start () {

Student[] student = new Student[3];

student[0] = new Student("ham", 100, 49, 29);

student[1] = new Student("ham1", 100, 49, 509);

student[2] = new Student("ham2", 100, 49, 29);

int max = int.MinValue;

Student maxStudent = null;

for( int i = 0; i < student.Length; i++)

{

if(max < student[i].Avg()){

max = student[i].Avg();

maxStudent = student[i];

}

}

print ("maxStudent");

maxStudent.ShowPrint();

}

// Update is called once per frame

void Update () {

}

}




'Computer Language > 유니티' 카테고리의 다른 글

오버로딩.  (0) 2014.04.21
goto문 2중 for문에서 합의하에 사용가능  (0) 2014.04.21
String.Format 잘 봐두자 유용하게 쓰인다.  (0) 2014.04.21
포맷 형식  (0) 2014.04.21
string 삭제 & 삽입  (0) 2014.04.15

    int a1 = 10;

string b1;

if(a1 == 0)

b1 = "ccc";

else

b1 = "abc";

print (b1);

int a = 0xF0;

int b = 0x0F;

string t1_1 = string.Format("a = {0:D}", a);

print (t1_1);

string t1 = string.Format("a = {0:X2}", a);

string t2 = string.Format("b = {0:X2}", b);

string t3 = string.Format("a|b = {0:X2}", a|b);

print (t1);

print (t2);

print (t3);

print (string.Format("{0:X4}", 1000));

print (string.Format("{0:N}", 10000));

print (string.Format("{0}", 10000));

print(string.Format("{0:D5}", 40));





'Computer Language > 유니티' 카테고리의 다른 글

goto문 2중 for문에서 합의하에 사용가능  (0) 2014.04.21
학생들 성적의 합과 평균 그리고 이름 찍기  (0) 2014.04.21
포맷 형식  (0) 2014.04.21
string 삭제 & 삽입  (0) 2014.04.15
letter  (0) 2014.04.15

   int a = 0xF0;

int b = 0x0F;

string t1 = string.Format("{0:X}", a);

string t2 = string.Format("{0:X}", b);

print (t1);

print (t2);

print (string.Format("{0:X4}", 1000));

print (string.Format("{0:N}", 10000)); //게임 점수 표시시 유용

print (string.Format("{0}", 10000));



'Computer Language > 유니티' 카테고리의 다른 글

학생들 성적의 합과 평균 그리고 이름 찍기  (0) 2014.04.21
String.Format 잘 봐두자 유용하게 쓰인다.  (0) 2014.04.21
string 삭제 & 삽입  (0) 2014.04.15
letter  (0) 2014.04.15
이동과 크기.  (0) 2014.04.14

nginex
php
코드이그나이터
restful

mysql (무료버전), workbench -> (sql)

'Computer Language > 하루하루' 카테고리의 다른 글

db 책  (0) 2014.06.11
게임 만들기  (0) 2014.06.10
사.  (0) 2014.06.07

+ Recent posts