마우스 클릭하면 랜덤으로 속도 변경해서 다른 결과 출력

룰렛이 돌면 기능 정지

인풋 필드에 이름 받아서 로그 찍음

 

할 일:

이름을 입력하면 클릭 글자 출력

글자 출력 후, 마우스 버튼을 누르면  씬이 넘어가게

입력한 이름이 게임 씬의 이름 란에 출력되게

게임 씬이 완료된 후, 이름 입력 씬으로 돌아오게 (이거 했는데 안됨; 왜 안돌아오냐...)

룰렛이 한 번만 돌게!

 

한글 폰트가 반은 되고 반은 안됨 ㅋ 아예 다 안써지면 말겠는데... 써지는 글자와 안써지는 글자가 있다...

  • 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 = Random.Range(5000, 50001); // 사이의 수를 돌리는 속도로 함
            Debug.Log(rotSpeed);

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

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

      //  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;
using UnityEngine.SceneManagement;

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

    public GameObject Good;
    public GameObject Bad;
    public GameObject Great;
    public GameObject GBad;
    public GameObject So;
    public GameObject CARE;

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

           ldelTime += Time.deltaTime;

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

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

    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name == "bedcoll")
        {
            Debug.Log("운수 나쁨");
            Bad.SetActive(true);
        }
        if (collision.name == "Goodcoll")
        {
            Debug.Log("운수대통");
            Great.SetActive(true);
        }
        if (collision.name == "Bedcolll")
        {
            Debug.Log("운수 매우 나쁨");
            GBad.SetActive(true);
        }
        if (collision.name == "socoll")
        {
            Debug.Log("운수 보통");
            So.SetActive(true);
        }
        if (collision.name == "bbedcoll")
        {
            Debug.Log("운수 조심");
            CARE.SetActive(true);
        }
        if (collision.name == "goodcoll")
        {
            Debug.Log("운수 좋음");
            Great.SetActive(true);
        }
        
        this.GameOver();
    }

    void GameOver()
    {
        Time.timeScale = 0f; // 작동 멈춤
      //  Debug.Log("게임오버");

        //if (Input.GetMouseButtonDown(1))
        //{
        ////    Debug.Log("탭탭");
        //    SceneManager.LoadScene("RoulletName");
        //}
    }
}

 

- 네임 입력 씬

  • GoRoulletScene
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
using UnityEngine.UI;

public class GoRoulletScene : MonoBehaviour
{
    public Button Button;
    public TMP_InputField InputText;
    public TMP_Text OutputText; // 테스트용

    private void Start()
    {

        this.Button.onClick.AddListener(() =>
        {
            OutputText.text = InputText.text;
            InputText.text = "";
             Debug.Log($"출력: {OutputText.text} 입력: {InputText.text}");
        });
    }

    private void Update()
    {
        if (this.Button != null) 
        {
            this.click(); // 이걸 어케켜?
        }

    }

    void click()
    {
        if (Input.GetMouseButtonDown(1))
        {
               Debug.Log("이동");
            SceneManager.LoadScene("SampleScene");
        }
    }
}

 

 

  • clickTXT : 깜박이
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class clickTXT : MonoBehaviour
{
    TMP_Text tmpTxt;

    void Start()
    {
        tmpTxt = GetComponent<TMP_Text>();

        StartCoroutine(coFadeIn());
    }

    IEnumerator coFadeIn() // 페이드인
    {
        tmpTxt.color = new Color(tmpTxt.color.r, tmpTxt.color.g, tmpTxt.color.b, 0); // 시작 시, 투명

        while (tmpTxt.color.a < 1.0f)
        {
            tmpTxt.color = new Color(tmpTxt.color.r, tmpTxt.color.g, tmpTxt.color.b, tmpTxt.color.a + (Time.deltaTime / 1.0f));
           
            yield return null;
        }
        StartCoroutine(coFadeOut());
        

    }

    IEnumerator coFadeOut() // 페이드아웃
    {
        tmpTxt.color = new Color(tmpTxt.color.r, tmpTxt.color.g, tmpTxt.color.b, 1);

        while (tmpTxt.color.a > 0f)
        {
            tmpTxt.color = new Color(tmpTxt.color.r, tmpTxt.color.g, tmpTxt.color.b, tmpTxt.color.a - (Time.deltaTime / 1.0f));
            yield return null;
        }
        StartCoroutine(coFadeIn());
    }
}

 

ㅎㅎ.. 이게 뭐라고 이렇게 오래 걸리지..

'└▶연습' 카테고리의 다른 글

룰렛5  (0) 2024.09.22
룰렛4  (1) 2024.09.22
룰렛2  (1) 2024.09.21
과일바구니3  (0) 2024.09.21
과일바구니2  (0) 2024.09.20

+ Recent posts