using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FunctionEx : MonoBehaviour
{
    // 리턴값이 없음
    // return을 사용하는 순간 함수 종료
    public void VoidFunction()
    {
        Debug.Log(message: "A");
        return;
        Debug.Log(message: "B"); // 출력되지 않음
    }

    public int MinusFunction(int x, int y)
    {
        return x-y;
    }

    public int[] Calculation1(int x, int y)
    {
        int result1 = x + y;
        int result2 = x - y;
        int result3 = x * y;
        int result4 = x / y;

        int[] result = { result1, result2, result3, result4 };

        return result;
    }

    public float[] Calculation2(float x, float y)
    {
        float result1 = x + y;
        float result2 = x - y;
        float result3 = x * y;
        float result4 = x / y;

        float[] result = { result1, result2, result3, result4 };

        return result;
    }
    
    public int Calculation3(int x, int y)
    {
        int result = 1;

        for(int i=0; i < y; i++)
        {
            result *= x;
        }

        return result;
    }

    private void Awake()
    {
        VoidFunction(); // 함수만 () 사용
        int result = MinusFunction(5, 3);
        Debug.Log(message: "마이너스 계산 결과1 : " + result);

        Debug.Log("마이너스 계산 결과2 : " + MinusFunction(5, 3));

        Debug.Log($"마이너스 계산 결과3 : {MinusFunction(5, 3)}"); // 문자열 보간법

        for(int i=0; i<4; i++)
        {
            Debug.Log($"정수형 계산 결과 : {Calculation1(5, 3)[i]}");
        }

        for (int i = 0; i < 4; i++)
        {
            Debug.Log($"실수형 계산 결과 : {Calculation2(5, 3)[i]}");
        }
        
        Debug.Log("x의 y제곱 값 :" + Calculation3(2, 5));
        
        Debug.Log($"제곱값 구하는 함수 : {Mathf.Pow(2, 5)}"); //
    }
}

 

Mathf.Pow()

제곱 값 구할 때 유니티에서는 Mathf.Pow() 함수 쓰면 된다.

 

문자열 보간법

프로그램 실행 중 문자열 내에 변수 또는 상수의 실질적인 값을 표현하기 위해 사용

$로 시작한 후 {}로 감싸서 사용한다.

Debug.Log($"사과는 {x}개");

오브젝트에 중력을 주어서 미끄러지게 만들기

 

미끄러질 오브젝트를 선택하여 중력을 적용해준다.

Add Component에서 Rigidbody를 추가해주면 된다.

 

Play 시 중력이 적용되어 미끄러진다.

화면 기본 이동은 마우스 오른쪽 버튼을 사용한다.

마우스 오른쪽 버튼을 누른채로 w, a, s, d키를 누르면 좀 더 세세하게 이동할 수 있다.

1.  Hand Tool 단축키 : Q

이동 전
이동 후

물체는 그대로 있고 화면만 움직일 수 있는 툴

마우스 휠을 눌러 사용할 수 있고, 툴을 선택하여 사용할 수도 있다.

 

 

2. Move Tool 단축키 : W

오브젝트를 이동시킬 수 있는 툴

Transform > Position에 직접 입력하여 오브젝트를 이동시킬 수 도 있다.

두 좌표 사이의 네모칸을 선택하면 두 좌표를 동시에 이동시킬 수도 있다.

 

3. Rotate Tool 단축키 : E

오브젝트 축을 회전하는 툴

Transform > Rotation에 직접 입력하여 오브젝트를 축을 회전할 수도 있다.

 

4. Scale Tool 단축키 : R

오브젝트 크기를 키울 수 있는 툴

큐브를 선택하여 크키를 키울 수 도 있고 Transform > Scale에 직접 입력하여 크키를 키울 수도 있다.

 

5. Rect Tool 단축키 : T

오브젝트의 y축과 z축을 이동시킬 수 있고, y축과 z축의 크기를 키울 수 있는 툴

3D보다는 2D를 이용할 때 사용하는 것이 좋을 것 같다.

 

6. Move, Rotate and Scale selected objects 단축키 : Y

Move Tool, Rotate Tool, Scale Tool을 동시에 사용할 수 있는 툴

 

+ Recent posts