요약 정리 

클래스란 무엇인가?

클래스는 컴퓨터 메모리에 있는 객체를 사용할 수 있는 설계도라 생각할 수 있다.
클래스는 객체에 사용할 수 있는 데이터와 기능을 저장한다. 

클래스는 또한, 객체에 속하지 않는 클래스 자체에 속하는 데이터와 기능을 저장할 수 있다.
이는 주로 전역적으로 이용되는 기능을 제공할 때 사용된다. 


접근 한정자(public, private, protected, internal) ?

사진 출처 : https://edmundtips.tistory.com/12

monobehaviour 이란?

게임 오브젝트에 custom behaviour를 프로그래밍하기 위해서 사용된다.
.Net프레임워크의 다중 프레임워크 구현인 Mono프로젝트를 사용함. 
(그래서 이름이 Mono + Behaviour임.)


namespace 란?

코드를 위한 도메인이라고 생각하면 된다. 
namespace는 코드를 조직화하고 이름간의 중복 오류로 인한 충돌을 방지한다.

namespace를 사용하기 위해서 계속 앞에 붙이는 것이 번거롭기에
컴파일러에게 미리 namespace를 찾아두라고 말할 수 있다. 
코드의 맨 앞에 using namespace;의 형태로 사용한다. 


structure란?

structure는 class와 유사하게 설계도의 역할을 합니다. 
다만, class와는 다르게 객체를 생성하는 것이 아닌, 값(정수 혹은 색상)을 생성합니다. 
class와 정의하는 방법이 같습니다. 


const란?

수정하지 않을 값. 필드(객체에서 속성, 변수)일 필요가 없음.
컴파일할 때 계산된다. 숫자와 같은 기본 유형에서만 가능함. 


시계 코드 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System
using UnityEngine;
 
public class Clock : MonoBehaviour 
{
    public Transform hoursTransform, minutesTransform, secondsTransform;
    const float degreesPerHour = 30f;
    const float degreesPerMinute = 6f;
    const float degreesPerSecond = 6f;
 
    public bool Continous; 
 
    private void Update()
    {
        if (Continous)
        {
            ContinousTime();
        }
        else
            DiscreteTime();
    }
 
    //digital적으로 시계추 움직임 
    private void DiscreteTime()
    {
        //시간 데이터 받아오기 
        DateTime time = DateTime.Now;
        //회전 
        hoursTransform.localRotation = Quaternion.Euler(0f, time.Hour * degreesPerHour, 0f);
        minutesTransform.localRotation = Quaternion.Euler(0f, time.Minute * degreesPerMinute, 0f);
        secondsTransform.localRotation = Quaternion.Euler(0f, time.Second * degreesPerSecond, 0f);
    }
 
    //analog적으로 시계추 움직임 
    private void ContinousTime()
    {
        //시간 데이터 받아오기 
        TimeSpan time = DateTime.Now.TimeOfDay;
        //회전 
        hoursTransform.localRotation = Quaternion.Euler(0f, (float)time.TotalHours * degreesPerHour, 0f);
        minutesTransform.localRotation = Quaternion.Euler(0f, (float)time.TotalMinutes * degreesPerMinute, 0f);
        secondsTransform.localRotation = Quaternion.Euler(0f, (float)time.TotalSeconds * degreesPerSecond, 0f);
    }
}
cs

완성된 영상 


관련링크 
https://catlikecoding.com/unity/tutorials/basics/game-objects-and-scripts/


Posted by 도이(doi)
,