참고영상

https://youtu.be/t1ucqZYx03E?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd 

 

 

6번 없음

6번 없음

참고영상

https://youtu.be/t1ucqZYx03E?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd

 

 

 

2번없음

2번없음

 

참고영상

https://youtu.be/t1ucqZYx03E?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd

 

 

 

참고영상

https://youtu.be/t1ucqZYx03E?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd

 

 

 

 

 

 

참고영상

https://youtu.be/t1ucqZYx03E?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd

 

 

참고영상

https://youtu.be/Bi-IK4uTBTg?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd
https://youtu.be/t1ucqZYx03E?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd

 

 

 

 

 

참고영상

https://youtu.be/Bi-IK4uTBTg?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd

 

 

 

참고영상

https://youtu.be/Bi-IK4uTBTg?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd

 

 

 

 

 

 

 

참고영상

https://youtu.be/Bi-IK4uTBTg?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd

 

 

참고영상

https://youtu.be/Bi-IK4uTBTg?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd

 

 

 

 

 

 

 

참고영상

https://youtu.be/Bi-IK4uTBTg?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd

 

 

 

 

참고영상

https://youtu.be/Bi-IK4uTBTg?list=PLC2Tit6NyVicvqMTDJl8e-2IB4v_I7ddd

 

 

 

논리 연산자

a && b //a and b, a 그리고 b 모두 참이면 참

a || b //a or b, a 또는 b 중에 하나라도 참이면 참

!a //a가 아니다 (논리 부정)

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     int a = 1;

     int b = 1;

     bool c;

     void Start()

     {

          c = !(a == b); //결과 True가 부정연산자 !(느낌표) 때문에 False가 됨

          print(c);

     }

}


비교 연산자

a < b //a가 b보다 작으면 참

a > b //a가 b보다 크면 참

a <= b //a가 b보다 작거나 같으면 참

a >= b //a가 b보다 크거나 같으면 참

a == b //a가 b와 같으면 참

a != b //a가 b와 다르면 참

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     int a = 10;

     int b = 5;

     void Start()

     {

          print(a < b);

          print(a > b);

          print(a <= b);

          print(a >= b);

          print(a += b);

          print(a != b);

     }

}

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

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     int a = 1;

     int b = 2;

     bool c;

     void Start()

     {

          c = a == b; // c = (a == b);

         print(c);

     }

}


대입 연산자

a += b // a = a + b

a -= b // a = a - b

a *= b // a = a * b

a /= b // a = a / b

a %= b // a = a % b

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     int a = 10;

     int b = 5;

     void Start()

     {

          print(a += b);

          print(a -= b);

          print(a *= b);

          print(a /= b);

          print(a %= b);

     }

}


증감 연산자

++

--

a++ // a = 1; b = a++; 결과 a(2) b(1)

++a // a = 1; b = ++a; 결과 a(2) b(2)

a-- // a = 2; b = a--; 결과 a(1) b(2)

--a // a = 2; b = --a; 결과 a(1) b(1)

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     int a = 1;

     int b = 1;

     void Start()

     {

          print(a++);

          print(++b);

     }

}


산술 연산자

a + b

a – b

a * b

a / b

a % b (a나누기 b의 나머지 값)

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     int a = 10;

     int b = 5;

     void Start()

     {

          print(a + b);

          print(a - b);

          print(a * b);

          print(a / b);

          print(a % b);

     }

}



using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

   int num = 0;

   void Start()

   {

      for (; ; )

      {

         num++;

         if (num % 2 == 0)

            continue;

         print(num);

         if (num > 10)

            break;

      }

   }

}

 

 

 

 

형식

for(초기식; 조건; 증감식) // 괄호 안에 있는 조건을 생략하면 다른 곳에 추가해야 한다.

{

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

}

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

   void Start()

   {

     int j = 0;

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

     {

       j = j + 1;

     }

     print(j);

   }

}

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

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

   int num = 0;

   void Start()

   {

      for (; ; )

     {

       num++;

       if (num % 2 == 0)

         continue;

       print(num);

       if (num > 10)

           break;

     }

   }

}

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

반복문 중첩하기

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     void Start()

     {

          for (int i = 2; i <= 9; i++)

          {

               for(int j = 1; j <= 9; j++)

               {

                    print(i + " + " + j + " = " + (i * j));

               }

          }

     }

}

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

 

 


참고영상
https://youtu.be/X1rHKZAVBvw?list=PLUZ5gNInsv_O7XRpaNQIC9D5uhMZmTYAf

변수를 선언한 위치에 따라
전역변수
지역변수 (함수가 호출되면 생성됐다가 함수가 리턴 되면 소멸된다)
매개변수


 

참고영상

https://youtu.be/X1rHKZAVBvw?list=PLUZ5gNInsv_O7XRpaNQIC9D5uhMZmTYAf

 

변수를 선언한 위치에 따라

전역변수

지역변수 (함수가 호출되면 생성됐다가 함수가 리턴 되면 소멸된다)

매개변수

 

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     int a = 100; // 전역변수, 멤버 변수, 필드

     void Start()

     {

          int b = 200; // 지역변수

          print(a);

          print(b);

     }

     void Test()

     {

          print(a); // 전역변수이기 때문에 사용 가능

          print(b); // 오류 발생, 지역변수 b는 다른 지역에서는 사용 불가, 선언한 곳에서만 사용 가능

     }

}

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

 

 

 

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     int a = 100; // 전역변수, 멤버 변수, 필드

     void Start()

     {

          Test1(); //함수 호출

          Test2(); //함수 호출

     }

     void Test1()

     {

          int b = 200; // 지역변수

          print(a);

          print(b);

     }

     void Test2()

     {

          print(a); // 전역변수이기 때문에 사용 가능

                         // print(b); // 오류 발생, 지역변수 b는 다른 지역에서는 사용불가, 선언한 곳에서만 사용가능

     }

}

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



 

 

지역변수, 같은 이름 다른 지역

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     int a = 100; // 전역변수, 멤버 변수, 필드

     void Start()

     {

          Test1(); //함수 호출

          Test2(); //함수 호출

     }

     void Test1()

     {

          int b = 200; // 지역 변수

          print(a);

          print(b);

     }

     void Test2()

     {

          int b = 300; // 지역 변수, Test1()함수의 지역 변수 b와 지역이 달라서 오류 없이 구별 사용한다.

          print(a); // 전역변수이기 때문에 사용 가능

          print(b); //

     }

}

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



 

 

전역변수와 지역변수 우선순위

 

전역 변수 a, 지역 변수 a와 같이 이름이 같으면 지역 변수의 우선순위가 높다

 

참고영상

https://youtu.be/X1rHKZAVBvw?list=PLUZ5gNInsv_O7XRpaNQIC9D5uhMZmTYAf&t=134

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     int a = 100; // 전역변수, 멤버 변수, 필드

     void Start()

     {

          Test1(); //함수 호출

          Test2(); //함수 호출

     }

     void Test1()

     {

          int b = 200; // 지역변수

          print(b);

     }

     void Test2()

     {

          int b = 300; // 지역변수

          print(b); // 전역변수이기 때문에 사용 가능

     }

}



 

결과 (전역 변수 a = 100은 무시 된다)

 

200

300

 

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

 

매개변수

참고영상

https://youtu.be/X1rHKZAVBvw?list=PLUZ5gNInsv_O7XRpaNQIC9D5uhMZmTYAf&t=173

 

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{

     int a = 100; // 전역변수, 멤버 변수, 필드

     void Start()

     {

          Test1(100); //함수 호출

          Test2(); //함수 호출

     }

     int Test1(int abc) //abc는 매개변수다. 리턴하기 위해 함수 자료형을 int로 변경함

     {

          abc += 200; // 매개변수

          return abc;

     }

     void Test2()

     {

          int b = 300; // 지역변수

          print("Test2 = " + b); // 전역변수이기 때문에 사용 가능

     }

}



 

 




+ Recent posts