using UnityEngine;

using System.Collections;


public class ExWhile5: MonoBehaviour {


// Use this for initialization

void Start () {

string[] npc_name = new string[]{"npc1", "npc2""npc3", "boss", "npc4"} ;

int[] npc_hp = new int[]{-100, -150, -200, -1000, -250} ;

int i;

string text;

int max_hp = int.MinValue; //at least error no minvalue

//float max_mp = float.MinValue;

int min_hp = int.MaxValue;

string max_name = "";

string min_name="";

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

text = npc_name[i] + "," + " [" + npc_hp[i] + "]";

print (text);

if( max_hp < npc_hp[i]){

max_hp = npc_hp[i];

  max_name = npc_name[i];

}

if( min_hp > npc_hp[i]){

min_hp = npc_hp[i];

min_name = npc_name[i];

}

}

print("max= " + max_hp + ", npc_name= " + max_name);

print ("min= " + min_hp + ", min_name= " + min_name);


}

// Update is called once per frame

void Update () {

}

}




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

변태같은 코드 ㅋㅋㅋ for문  (0) 2014.04.04
pow 2의 제곱승 2014 출력하기  (0) 2014.04.04
while문& for문 별찍기 놀이  (0) 2014.04.04
while  (0) 2014.04.04
배열  (0) 2014.03.31

1. 이중 while

using UnityEngine;

using System.Collections;


public class ExWhile4 : MonoBehaviour {

void Start(){

int[] count = new int[]{7, 2, 3, 4, 5, 4, 3, 4, 1, 0} ;

int row = -1;

int col = 0;

int sum = 0;

string text = " ";

while(true){

row += 1;

print (count[row]);

if(count[row] == 0){

break;

}

col = 0;

text = " ";

while(col<count[row]){

col +=1;

text = text + "*";

}

print (text);

}

}

}



2. 2중 for

using UnityEngine;

using System.Collections;


public class ExWhile4 : MonoBehaviour {

void Start(){

int[] count = new int[]{7, 2, 3, 4, 5, 4, 3, 4, 1, 0} ;

int row = -1;

int col = 0;

int sum = 0;

string text = " ";

for(row = 0; count[row]>0; row++){

//print(count[row]);

text = " ";

for(col = 0; col < count[row]; col++){

text = text + "*";

}

print (text);

}

}

}

3. while문 for문

using UnityEngine;

using System.Collections;


public class ExWhile4 : MonoBehaviour {

void Start(){

int[] count = new int[]{7, 2, 3, 4, 5, 4, 3, 4, 1, 0} ;

int row = -1;

int col = 0;

int sum = 0;

string text = " ";

while(true)

{

row++;

if(count[row]==0){

break;

}

col = 0;

text = " ";

//for

for(col =0; col < count[row]; col++){

text = text + "*";

}

print(text);

// }

}

}

}



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

pow 2의 제곱승 2014 출력하기  (0) 2014.04.04
npc 최대값 최소값 이름 출력  (0) 2014.04.04
while  (0) 2014.04.04
배열  (0) 2014.03.31
C# String Format  (0) 2014.03.31

using UnityEngine;

using System.Collections;


public class ExWhile : MonoBehaviour {


// Use this for initialization

void Start () {

string[] names = new string[]{

"Hello", "Inha", "Pass","Pass1", "Quit", "Morning" 

} ;

int i = -1;

while(true){

i++;

if(names[i] == "Pass"){

continue;

}

if(names[i] == "Pass1"){

continue;

}

print (names[i]);

if(names[i] == "Quit")

break;

}

}

// Update is called once per frame

void Update () {

}


}

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

npc 최대값 최소값 이름 출력  (0) 2014.04.04
while문& for문 별찍기 놀이  (0) 2014.04.04
배열  (0) 2014.03.31
C# String Format  (0) 2014.03.31
형변환  (0) 2014.03.31

void Start () {

int[] numbers = new int[5]{10, 30, 40, 50, 70} ;

string[] names = new string[3]{"KIM", "Lee", "Park"} ;

float[] numbers2 = new float[]{10.2f, 30.4f, 40.5f, 50.6f, 70.33f} ;

int i;

int max = 0;

int sum = 0;

string text;

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

//if(max < numbers[i])

// max = numbers[i];

text = string.Format("names[{0}] = {1:F3}" , i, numbers2[i]);

print (text);

}

print ("max = " + max);

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

sum = numbers[i] + sum;

}

print ("Rank = " + ((System.Array)numbers).Rank);

print ("sum=" + sum);

}



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

while문& for문 별찍기 놀이  (0) 2014.04.04
while  (0) 2014.04.04
C# String Format  (0) 2014.03.31
형변환  (0) 2014.03.31
boolean  (0) 2014.03.31

void ShowStringFormat2 ()

{

// C# string format 

string s = string.Format (

        "(C) Currency: . . . . . . . . {0:C}\n" +

        "(D) Decimal:. . . . . . . . . {0:D}\n" +

        "(E) Scientific: . . . . . . . {1:E}\n" +

        "(F) Fixed point:. . . . . . . {1:F5}\n" +

        "(G) General:. . . . . . . . . {0:G}\n" +

        "    (default):. . . . . . . . {0} (default = 'G')\n" +

        "(N) Number: . . . . . . . . . {0:N0}\n" +

        "(P) Percent:. . . . . . . . . {1:P}\n" +

        "(R) Round-trip: . . . . . . . {1:R}\n" +

        "(X) Hexadecimal:. . . . . . . {0:X}\n",

        12300, -12300.45678f); 

print (s);

}



Number가 주로 잘 쓰입니다.

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

while  (0) 2014.04.04
배열  (0) 2014.03.31
형변환  (0) 2014.03.31
boolean  (0) 2014.03.31
이스케이프 문자  (0) 2014.03.31


using UnityEngine;

using System.Collections;


public class Chap3 : MonoBehaviour {


// Use this for initialization

void Start () {

byte a = 250;   //0~255

short b = a;       //-32765 ~ 32765

ushort c = 2000; //65535

sbyte d = (sbyte)c;         //-128~127 

print("b =" + b);  

print ("d=" + d);

}

// Update is called once per frame

void Update () {

}

}

가지고 있는 값보다 크다면 형변환을 해줘야 함. 하지만 그 값은 범위내에 있어야 제대로 표현됨.

범위내에 없다면 다른 값을 리턴

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

배열  (0) 2014.03.31
C# String Format  (0) 2014.03.31
boolean  (0) 2014.03.31
이스케이프 문자  (0) 2014.03.31
문자형  (0) 2014.03.31

using UnityEngine;

using System.Collections;


public class Chap3 : MonoBehaviour {


// Use this for initialization

void Start () {

//bool isStudent = false;

System.Boolean isStudent = false;

int age1 = 10;

int age2 = 30;

if(age1<19)

isStudent = true;

else

isStudent = false;

print ("age1 isStudent ="  + isStudent);

if(age2<19)

isStudent = true;

else

isStudent = false;

print ("age2 isStudent ="  + isStudent);

}

// Update is called once per frame

void Update () {

}


int age1 = 10;

bool isArmy = 20 <=age1  && age1 < 30;

print("age1 isStudent = " + isArmy);



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

C# String Format  (0) 2014.03.31
형변환  (0) 2014.03.31
이스케이프 문자  (0) 2014.03.31
문자형  (0) 2014.03.31
실수를 많이 해서 실수형.  (0) 2014.03.31

void Start () {

string text = @"\tHello\nWorld";

print (text);

string text2 = "\\tHello\\nWorld";

print (text2);

string text3 = "\tHello\nWorld";

print (text3);

}

}


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

형변환  (0) 2014.03.31
boolean  (0) 2014.03.31
문자형  (0) 2014.03.31
실수를 많이 해서 실수형.  (0) 2014.03.31
자료형(실수)  (0) 2014.03.31

public class Chap3 : MonoBehaviour {


// Use this for initialization

void Start () {

char ch1 = 'a';

char ch2 = 'b';

char ch3 = '\\';

char t = '\t';

char n = '\n';

string e = "Hello" + n + t + t + "World";   //앞에 더 크면 뒤에꺼 자동 형변환 해줌니다.

string a = "Hello, World";

string b = "Hello,\tWorld";

string c = "Hello,\nWorld";

string d = e + c;

print ("ch1 " + ch1);

print ("ch2 " + ch2);

print ("ch3 " + ch3);

print ("a " + a);

print ("b" + b);

print ("c " + c);

print ("d" + d);

}

// Update is called once per frame

void Update () {

}

}


char 2바이트 연산이 안된다. char tostring으로 바꿔줘야 한다.




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

boolean  (0) 2014.03.31
이스케이프 문자  (0) 2014.03.31
실수를 많이 해서 실수형.  (0) 2014.03.31
자료형(실수)  (0) 2014.03.31
자료형(정수)  (0) 2014.03.31

using UnityEngine;

using System.Collections;


public class Chap3 : MonoBehaviour {


// Use this for initialization

void Start () {

float f1 = 0.1f - 0.2f;

float f2 = 43.1f - 43.2f;

double d3 = 0.1 - 0.2;

print("0.1-0.2=" + f1);

print ("43.1f-43.2f = " + f2);

if(f1 == f2)

{

print("Equal");

}

else{

print ("Not Equal");

}

}

// Update is called once per frame

void Update () {

}

}

실수형은 실수를 많이 한다.


using UnityEngine;

using System.Collections;


public class Chap3 : MonoBehaviour {


// Use this for initialization

void Start () {

decimal a = 0.1m - 0.2m;

decimal b = 43.1m - 43.2m;

print (" 0.1m - 0.2m = " + a);

print (" 43.1m - 43.2m = " + b);

if(a == b)

print ("equal");

else

print ("Not Equal");

}

// Update is called once per frame

void Update () {

}

}
decimal은 오차가 없다




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

이스케이프 문자  (0) 2014.03.31
문자형  (0) 2014.03.31
자료형(실수)  (0) 2014.03.31
자료형(정수)  (0) 2014.03.31
왼쪽 오른쪽 이동 그리고 정지  (0) 2014.03.31

+ Recent posts