Unity/수업 내용

[Unity 2020.3] 룰렛 프로젝트

JSH1 2021. 10. 4. 18:13

세팅


스크립트

public class RouletteController : MonoBehaviour
{
    float rotSpeed = 0;

    void Update()                           //  0: 왼쪽 버튼, 1: 오른쪽 버튼, 2: 휠
    {
        if(Input.GetMouseButtonDown(0))
        {                                   //  ButtonDown: 버튼을 눌렀을 때
            Debug.Log("Down");
        }

        if(Input.GetMouseButton(0))         //  Button: 버튼을 누른 상태로 유지 중일 때
        {
            this.rotSpeed = 50;
        }

        if(Input.GetMouseButtonUp(0))       // ButtonUp: 버튼에서 손을 뗐을 때
        {
            Debug.Log("Up");
        }

        transform.Rotate(0, 0, this.rotSpeed);  //  Z축으로 회전

        this.rotSpeed *= 0.96f;                 //  회전속도 감속
    }
}

실행 결과