└▶연습

룰렛2

101won 2024. 9. 21. 19:12

운수대통만 나오네. 좋긴한데..

 

니들과 룰렛판에 콜리전을 붙이서 나온 글자를 UI에 띄우려함

- 멈추면 니들의 콜라이더가 활성화 < 돌리지 않은 0 상태가 시작이라 콜라이더가 활성화 되었음

- 룰렛을 돌릴 때 시간을 체크해 콜라이더 활성 조건에 시간이 0이 아니면을 추가함

>> 룰렛을 돌리는 속도(힘)과 멈추는 힘이 같아서 항상 같은 자리에서 멈춤

 

  • Roullet
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class Roullet : MonoBehaviour
{
    float rotSpeed;
    float delta = 0;
    public bool isStop = false; // 멈추면 트루로 변경해서 니들이 받음

    void Update()
    {
        // 마우스를 클릭하면 지정 속도로 룰렛이 돈다.
        if(Input.GetMouseButtonUp(0))
        {
            this.rotSpeed = 50000; // 버튼을 누르면 작동

            delta += Time.deltaTime;
        }
         //   Debug.Log(delta);
            transform.Rotate(0, 0, rotSpeed);

        // 속도를 줄인다.
        this.rotSpeed *= 0.99f;

      //  Debug.Log(this.rotSpeed);

        if (this.rotSpeed < 2 && delta !=0)
        {
            this.rotSpeed = 0f;

            isStop = true;
          //  Debug.Log($"<color=yellow>멈춤</color>");
        }
    }
}

 

  • needle
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class needle : MonoBehaviour
{
    public GameObject Roullet;
    float ldelTime = 0;

    private void Update()
    {
        if((Roullet.GetComponent<Roullet>().isStop == true))
        {
           Debug.Log($"<color=blue>왔어</color>");

           ldelTime += Time.deltaTime;

            if (ldelTime > 1)
            {
                // Debug.Log("1초");

                // 니들 콜라이더 활성화
                this.GetComponent<Collider2D>().enabled = true;
            }
        }
    }

    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name == "bedcoll")
        {
            Debug.Log("운수 나쁨");
        }
        if (collision.name == "Goodcoll")
        {
            Debug.Log("운수대통");
        }
        if (collision.name == "Bedcolll")
        {
            Debug.Log("운수 매우 나쁨");
        }
        if (collision.name == "socoll")
        {
            Debug.Log("운수 보통");
        }
        if (collision.name == "bbedcoll")
        {
            Debug.Log("운수 조심");
        }
        if (collision.name == "goodcoll")
        {
            Debug.Log("운수 좋음");
        }
    }
}