UNITY/Unity Study

운수룰렛 스와이프로 바꾸기

GREEN나무 2023. 7. 5. 19:27
728x90

클릭해서 돌리기

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

public class RouletteController : MonoBehaviour
{
    float rotSpeed =0; //회전 속도

    // Start is called before the first frame update
    void Start()
    {
        // 프레임레이트를 60으로 고정한다.
        Application.targetFrameRate = 60;

    }

    // Update is called once per frame
    void Update()
    {
        // 클릭하면 회전속도를 설정함
        if (Input.GetMouseButtonDown(0)){
            this.rotSpeed = 10;
        }
        // 회전 속도만큼 룰렛 회전
        transform.Rotate(0,0, this.rotSpeed);
        // 룰렛 속도 감소
        this.rotSpeed *= 0.96f;
    }
}

 

스와이프로

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

public class RouletteController : MonoBehaviour
{
    float rotSpeed =0; //회전 속도
    Vector2 startPos;
    // Start is called before the first frame update
    void Start()
    {
        // 프레임레이트를 60으로 고정한다.
        Application.targetFrameRate = 60;

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            this.startPos = Input.mousePosition;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            Vector2 endPos = Input.mousePosition;
            float swipeLength = endPos.x - this.startPos.x;
            this.rotSpeed = swipeLength / 50.0f;
        }
        // 회전 속도만큼 룰렛 회전
        transform.Rotate(0,0, -this.rotSpeed);
        // 룰렛 속도 감소
        this.rotSpeed *= 0.96f;
    }
}

'UNITY > Unity Study' 카테고리의 다른 글

유니티 시민강좌 2일차  (0) 2023.07.19
유니티 시민강좌 1일차  (0) 2023.07.17
카메라 컨트롤  (0) 2023.07.05
메티리얼 문양 크기편집  (0) 2023.07.05
인벤토리2 (인벤토리창에 아이템이 안뜸)  (0) 2023.07.05