(유니티 unity) c#, 자료형

 

int 정수 (약 -21억 ~ +21억)             int aa = 100;
long 정수 (약 -922경 ~ +922경)      long nn = 1000000;
float 실수 (소수 6자리)                   float ff = 0.1f;
double 실수 (소수 14자리)             double dd = 0.111111d;
string 문자열                                  string tt = “test”
bool 참(true), 거짓(false)                bool bb = false;
char 문자 1글자                              chr cc = 'a';
short 정수 (약 -6만 ~ +6만)

 

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class NewBehaviourScript : MonoBehaviour

{

     int gold = 500;

     long money = 10000000000;

     float half = 0.5f;

     double d = 1.1111d;

     string word = "Helo Would";

     bool Check = false;

     char ch = 'c';

     void Start()

     {

          print(gold);

          print(money);

          print(half);

          print(d);

          print(word);

          print(Check);

          print(ch);

     }

}

 

 

 

 

배열형식:

자료형[] 변수 = {원소, 원소,...}; int[] exp = { 10, 20, 30 };

 

자료형[] 변수 = new 자료형[개수]; int[] aa = new int[5];

 

2차원 배열

자료형[,] 변수 = {{원소, 원소,...}, {원소, 원소,...}};

int[,] exp2 = { { 10, 20, 30 }, { 100, 200, 300 } };

3차원 배열

자료형[,] 변수 = {{{원소, 원소,...}, {원소, 원소,...}},{{원소, 원소,...}, {원소, 원소,...}}};

int[,,] exp3 = { { { 10, 20, 30 }, { 100, 200, 300 } }, { { 10, 20, 30 }, { 100, 200, 300 } } };

 

배열길이

배열이름.Length

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

{

aa[i] = i+100;

Debug.Log(aa[i]);

}

 

int[] aa = { 1, 2, 3, 4, 5 };

int[] bb = new int[aa.Length];

 

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class NewBehaviourScript : MonoBehaviour

{

// Start is called before the first frame update

void Start()

{

// 1차원 배열

int[] exp = { 10, 20, 30 };

print(exp[1]);

 

// 2차원 배열

int[,] exp2 = { { 10, 20, 30 }, { 100, 200, 300 } };

print(exp2[0, 1]);

 

// 3차원 배열

int[,,] exp3 = { { { 10, 20, 30 }, { 100, 200, 300 } }, { { 10, 20, 30 }, { 100, 200, 300 } } };

print(exp3[0, 0, 1]);

}

}

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class NewBehaviourScript : MonoBehaviour

{

 

// Start is called before the first frame update

void Start()

{

int[] bb = { 1, 2, 3, 4, 5 }; //배열을 선언하고 원소를 넣기

 

int[] aa = new int[5]; //배열의 크기만 선언하기

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

{

aa[i] = i+100;

Debug.Log(aa[i]);

}

}

}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class NewBehaviourScript : MonoBehaviour

{

// Start is called before the first frame update

void Start()

{

int highOrc = 0;

string Name = "";

int[] orc = new int[5];

orc[0] = 1;

orc[1] = 50;

orc[2] = 70;

orc[3] = 30;

orc[4] = 40;

 

for (int i = 0; i < 5; i++) // for (int i = 0; i < orc.Length ; i++)

{

if (orc[i] >= highOrc)

{

highOrc = orc[i];

Name = "orc" + (i + 1);

}

}

Debug.Log(Name + ", " + highOrc);

}

}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class NewBehaviourScript : MonoBehaviour

{

// Start is called before the first frame update

void Start()

{

int[] aa = { 1, 2, 3, 4, 5 };

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

{

Debug.Log(aa[i]); // i는 인덱스(색인)다

}

 

}

}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class NewBehaviourScript : MonoBehaviour

{

// Start is called before the first frame update

void Start()

{

int[] aa = { 1, 2, 3, 4, 5 };

int[] bb = new int[aa.Length];

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

{

bb[i] = aa[i];

Debug.Log("bb[" + i + "] ===> " + bb[i]);

}

}

}

 

 

참고영상

https://youtu.be/1EunT7hrpVE?list=PLO7uIclOcS0jkOVyF-f_Ms5qp-UuGHYog

https://youtu.be/pRq1U5UmXCU?t=35

 

 

 

형식

while(조건)

{

   조건이 참인 경우 실행할 명령어들

}

 

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class NewBehaviourScript : MonoBehaviour

{

   void Start()

   {

      int i = 0;

      while(i < 100)

      {

         i++;

      }

      Debug.Log(i);

   }

}

 

 

참고영상

https://youtu.be/AdLTj4WR8eE?list=PLO7uIclOcS0jkOVyF-f_Ms5qp-UuGHYog

 

 

참고영상

https://youtu.be/jcHwEtCGAqA?list=PLO7uIclOcS0jkOVyF-f_Ms5qp-UuGHYog&t=24

 

 

참고영상

https://youtu.be/Qle2ke9RkLk?list=PLO7uIclOcS0jkOVyF-f_Ms5qp-UuGHYog&t=1220

 

 

 

참고영상

https://youtu.be/Qle2ke9RkLk?list=PLO7uIclOcS0jkOVyF-f_Ms5qp-UuGHYog&t=900

 

 

 

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Class_연습2 : MonoBehaviour

{

   // Start is called before the first frame update

   void Start()

   {

      Orc클래스 orc1 = newOrc클래스();

      orc1.orc이름 = "파란색 오크";

      print("오크 이름 ===> "+ orc1.orc이름);

   }

}

classOrc클래스

{

   public string orc이름;

   public int orc공격력;

   public int orc방어력;

   public void orc대기기능() { }

   public void orc공격기능() { }

   public void orc사망기능() { }

}

참고영상

https://youtu.be/TfoOe_q719E?list=PLO7uIclOcS0jkOVyF-f_Ms5qp-UuGHYog&t=381

 

 

 

 

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Class_연습2 : MonoBehaviour

{

   // Start is called before the first frame update

   void Start()

   {

      Ufo클래스 a홍길동주소 = new Ufo클래스();

      Ufo클래스 b손오공주소 = new Ufo클래스();

      a홍길동주소.s이름변수 = "홍길동";

      b손오공주소.s이름변수 = "손오공";

      a홍길동주소 = b손오공주소;

 

      print("a홍길동주소 ===> "+ a홍길동주소.s이름변수);

      print("b손오공주소 ===> "+ b손오공주소.s이름변수);

   }

}

class Ufo클래스

{

   public strings 이름변수;

   public int p파워변수 = 80;

   public void Ufo테스트() { }

}

using UnityEngine;

public class Class_연습 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        UFO_달리기_자식_클래스 ufo_변수 = new UFO_달리기_자식_클래스();
        ufo_변수.ufo_공격함수();
    }
}

public class UFO_부모_클래스      // 클래스
{
    public void ufo_대기함수()     // Ufo_대기 함수
    {
        int second = 3;
        Debug.Log("플레이어가 없으면" + second + "초 대기 중");
    }
    public void ufo_공격함수() 
    { 
        Debug.Log("===> 공격함수"); 
    }
}

public class UFO_달리기_자식_클래스 : UFO_부모_클래스       // 클래스 상속
{
    
    public void ufo_공격함수() 
    {
        base.ufo_공격함수();
    }
    public void ufo_달리기함수() 
    { 
        Debug.Log("===> 달리기함수"); 
    }

}

참고영상

https://youtu.be/BhLcMrEAlfc

 

 

 

+ Recent posts