대외활동/starters 부트캠프 feat.웅진씽크빅

유데미 스타터스 취업 부트캠프 유니티 1기 3주차 학습 일지 -1

Heeyeon Choi 2022. 7. 4. 12:36
728x90

<유니티 체험하기>

- 3D 오브젝트들을 생성

- cube 오브젝트에 스크립트 생성
- public Rigidbody r 을 생성하여 inspecter 창에서 큐브 넣기

- 스크립트에 MovePosition(new Vector3(0,1,0))를 설정하여 게임 내에서 위치 조정 

 

 

<유니티에서 C#을 사용하는 이유?>

Mono Framework(Tamarin)

 

<C# in Unity>

- cs (csharp) 

- meta 

728x90

<MonoBehaviour >

- class 옆에 붙여줘야 스크립트를 오브젝트에 붙일 수 있음

 

 

생명주기

Awake()

onEnable()

start()

update()

TriggerEnter()

onDisable()

 

 

<프로그래밍 기초>

변수 - 명사 , 변하는 값을 넣을 수 있음

함수 - 동사

변수 선언- 자료형 변수이름  = 값 ; 

 

자료형

 

정수

short - 2byte
int - 4byte
long - 8byte

실수

float - 4byte
double - 8byte

문자

char - 1byte
string 
Debug.Log("Hello! World.");
Debug.Log(_strSample);

bool

주의) True, False 만 가능 -> 1, 0 불가능
Debug.Log(_strSample[0] == _chSample);

 

부동소수점(float)

부동- 떠다닌다란 뜻

지수 고정x

 

고정소수점(decimal) - 지수 고정

가수 밑수 지수 

예) 4.123

가수: 4123 

정확성, 용량이 큼

금융권 - > 정확성때문

 

0.1f-> f 안 붙이면 double 로 인식

 double  - float = 오차

 

 

 

- float에서 등치 비교는 안 쓰는게 좋음 

 // 부동소수점 고정소수점
Debug.Log(_numberWithFloat1 - 0.1);
Debug.Log(_numberWithFloat1 - 0.1f);
Debug.Log(_numberWithFloat2 - 0.1);
Debug.Log(_numberWithFloat2 - 0.1f);
//Debug.Log(_numberWithFloat3 - 0.1f);
//Debug.Log(_numberWithFloat3 - 0.1);
Debug.Log(_numberWithFloat3 - 0.1m);

 

 

연산자

 

산술연산자

이항연산자

        // 이항 연산자
        var arithmetic = 5;
        arithmetic = arithmetic + 9;
        Debug.Log(arithmetic);  // output: 14
        arithmetic = arithmetic - 4;
        Debug.Log(arithmetic);  // output: 10
        arithmetic = arithmetic * 2;
        Debug.Log(arithmetic);  // output: 20
        arithmetic = arithmetic / 4;
        Debug.Log(arithmetic);  // output: 5
        arithmetic = arithmetic % 3;
        Debug.Log(arithmetic);  // output: 2

복합대입연산자

        arithmetic = 5;
        // 복합 대입 연산자
        arithmetic += 9;
        Debug.Log(arithmetic);  // output: 14
        arithmetic -= 4;
        Debug.Log(arithmetic);  // output: 10
        arithmetic *= 2;
        Debug.Log(arithmetic);  // output: 20
        arithmetic /= 4;
        Debug.Log(arithmetic);  // output: 5
        arithmetic %= 3;
        Debug.Log(arithmetic);  // output: 2

증감연산자

        // 증감연산자
        Debug.Log(++arithmetic);
        Debug.Log(arithmetic++);
        Debug.Log(arithmetic);
        Debug.Log(--arithmetic);
        Debug.Log(arithmetic--);
        Debug.Log(arithmetic);

 

비교연산자

==, >=, <=, <, > 

 

논리연산자

&&, || 
&, | 

&&

(true && true) == true
(false && true) ==false
(false && false) == false

||

(true||flase) == true

 

형변환

암시적

변환 될 자료형을 입력하지 않아도 되는 형변환
작은 범위의 자료형에서 넓은 범위의 자료형으로 변환할 때 일어남
int _number = 123;
float afterFloat = _number;
double afterDouble = _number;

명시적

코드에 직접 변환 될 자료형을 입력
int afterInt = (int)_numberWithFloat1;
afterFloat = (float)afterDouble;

 

etc.

var의 사용에 관하여
- js의 var와는 다릅니다
- 형을 구분할 수 있고, 값을 지정해줘야 하기 때문입니다
- 단, 숫자 내장 숫자타입 사용시 var는 주의해야 합니다
- 전역변수x,  값 지정 필요합니다
연산자 우선순위
최우선연산자 ( ., [], () )
단항연산자 ( ++,--,!,~,+/- : 부정, bit변환>부호>증감)
산술연산자 ( *,/,%,+,-,shift)
< 시프트연산자 ( >>,<<,>>> ) >
비교연산자 ( >,<,>=,<=,==,!= )
비트연산자 ( &,|,,~ )
논리연산자 (&& , || , !)
삼항연산자 (조건식) ? :
대입연산자 =,*=,/=,%=,+=,-=
코드표기법(회사마다 다름)
- 파스칼케이스 
-카멜케이스

 

 

——————————————————————————

유데미코리아 바로가기 : https://bit.ly/3b8JGeD

본 포스팅은 유데미-웅진씽크빅 취업 부트캠프 유니티 1기 과정 후기로 작성되었습니다.

728x90