Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
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
Tags
more
Archives
Today
Total
관리 메뉴

8 STRENGTH

중간 점검) 유니티 기본 C# 문법 정리 1 본문

유니티

중간 점검) 유니티 기본 C# 문법 정리 1

다민 2022. 7. 24. 22:12

Debug.Log(“~~~”);

디버그 멘트를 콘솔창에 띄워줌.

void Start()
{
	Debug.Log("프로그램 시작");
}

 

 

 

Time.deltaTime

프레임, 즉 컴퓨터의 사양에 관계 없이 오브젝트가 동일한 속도로 움직일 수 있도록 함. ‘이동이나 회전 등 움직임에 있어서 시간의 영향을 받는 기능을 만들 때에는 값에 deltaTime을 곱해서 흘러간 프레임 시간만큼만 가중치를 줌으로써 프로세서 속도의 영향에서 자유로워짐

참고할 글 : https://wergia.tistory.com/313

 

HP = -1.0f * Time.deltaTime;
h = h * speed * Time.deltaTime;

 

 

 

Input.GetMouseButtonDown(숫자)

숫자가 0일 때 : 왼쪽 마우스 버튼 클릭

숫자가 1일 때 : 오른쪽 마우스 버튼 클릭

숫자가 2일 때 : 마우스 휠 클릭

 

if (Input.GetMouseButtonDown(0)) {}

왼쪽 마우스 버튼이 클릭됐을 때

참고할 글 : https://8strength.tistory.com/4

https://8strength.tistory.com/5

 

 

 

+ Input.GetMouseButtonUp(숫자)는 이와 반대. 스와이프를 구현할 때 사용함

참고할 글 : https://8strength.tistory.com/5

 

 

 

Vector2

2D 프로젝트에서 좌표를 표현하는 데이터. 말 그대로 벡터!

참고할 글 : https://hotstudy.tistory.com/93

ex) Vector2 startPos = Input.mousePosition;

 

 

 

Input.mousePosition

마우스 위치를 불러옴

 

if (Input.GetMouseButtonDown(0))
	{
    	Vector2 startPos = Input.mousePosition;
	}
else if (Input.GetMouseButtonUp(0))
	{
    	Vector2 endPos = Input.mousePosition;
	}
    
float Length = endPos.x - startPos.x;

 

 

 

transform.Translate(변수1, 변수2, 0);

2D에서 움직임을 진행하는 기능

참고할 글 : https://8strength.tistory.com/5

 

transform.Translate(speed, 0, 0);

 

 

 

transform.Rotate(0, 0, 변수);

2D에서 회전을 진행하는 기능. 2D에서 회전은 z, 3D라면 xyz에서 모두 회전 가능할 듯.

참고할 글 : https://8strength.tistory.com/4

 

transform.Rotate(0, 0, RotationSpeed);

 

 

 

Input.GetAxis, Input.GetAxisRaw

키보드 및 마우스의 (벡터 형태로 볼 수 있는 이동에 대한) input을 수직, 수평 벡터로 분해하여 각각의 벡터 크기값을 가져오는 기능... 이라고 이해된다(잘 모르겠음). 대충 방향키 키보드를 오래 누르고 있으면 그 이동 벡터의 크기가 커지고, 그만큼 더 많은 거리를 이동하게 되는 것 같음. 출력값은 float.

 

Input.GetAxis("Horizontal")은 위로 이동할 때 +, 아래로 이동할 때 -의 값을 가지고, Input.GetAxis("Vertical")은 오른쪽으로 이동할 때 +, 왼쪽으로 이동할 때 -의 값을 가진다.

 

이 값을 상수와 Time.deltaTime을 곱해 얼마나 (빠르게) 이동시킬 지 정할 수 있다. 실제 이동의 형태는

transform.Translate(Vector2.right * 수평이동의값변수)

transform.Translate(Vector2.up * 수직이동의값변수)

로 표현된다.

참고할 글 : https://keemeesuu.github.io/2021/unity/Input

https://8strength.tistory.com/6

 

    void Update()
    {
        // 수평, 수직 입력(이동 기능 구현)
        // 수평(Horizontal), 수직(Vertical)

        // 키보드 입력
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        // 이동 속도 보정
        h = h * speed * Time.deltaTime;
        v = v * speed * Time.deltaTime;

        //Time.deltaTime : The time in seconds it took to complete the last frame
        //                 한 프레임이 완료되기까지 걸리는 시간. 주로 움직임에서 이 값을 곱하여 프레임 당 이동을 구현하는 용도로 활용
        //                 성능의 영향을 받음.

        // 실제 이동
        transform.Translate(Vector2.right * h);
        transform.Translate(Vector2.up * v);
    }

 

 

 

회전

https://8strength.tistory.com/4

 

 

 

스와이프

https://8strength.tistory.com/5

 

5일차 스와이프의 GameDirector.cs, 6일차 화살 피하기 게임 정리 필요.