현재 룰렛은 8등분이 되어 있고
각각 360 / 8인 45도로 구성되어 있다.
그러므로 이 가운데 값은 22.5도이다.
룰렛을 개발자가 편하게 컨트롤 할 수 있도록 만들었다.
360도 * 횟수를 적용하여 여러번 돌아가고 거기에 지정한 extraAngle을 더해주면된다.
회전횟수를 선택할 수 있고 스탭을 조절함으로서 속도를 조절할 수 있다.
아래는 개발자들은 이미 사전에 클릭을 하면 알 수 있게 항목을 출력하도록 변경
나오는 것은 랜덤으로 변경
즉, 랜덤에 따라 특정 각도가 결정되고 그에 따라 개발자들은 출력결과를 미리 알수 있고,
유저들은 원하는 각도를 보게 되는 것이다.
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.UI;
public class RouletteTest : MonoBehaviour
{
[SerializeField] private Button btnGetIem;
[SerializeField] private Roulette _roulette;
//[SerializeField] private float targetAngle = -22.5f; //클로버를 겨냥
private string[] itemNames = { "폭탄" , "기력회복", "폭탄", "체력회복", "폭탄", "금화획득","폭탄", "네잎클로버"};
private float[] targetAngles =
{
22.5f, 67.5f, 112.5f, 157.5f, 202.5f, 247.5f, 292.5f, 337.5f
};
void Start()
{
btnGetIem.onClick.AddListener(() =>
{
int idx = UnityEngine.Random.Range(0, 8); // 0 ~ 7
Debug.Log($"<color=yellow>{itemNames[idx]}</color>");
_roulette.StartRotate(targetAngles[idx]);
});
}
}
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.UI;
public class RouletteTest : MonoBehaviour
{
[SerializeField] private Button btnGetIem;
[SerializeField] private Roulette _roulette;
//[SerializeField] private float targetAngle = -22.5f; //클로버를 겨냥
private string[] itemNames = { "폭탄" , "기력회복", "폭탄", "체력회복", "폭탄", "금화획득","폭탄", "네잎클로버"};
private float[] targetAngles =
{
22.5f, 67.5f, 112.5f, 157.5f, 202.5f, 247.5f, 292.5f, 337.5f
};
void Start()
{
btnGetIem.onClick.AddListener(() =>
{
int idx = UnityEngine.Random.Range(0, 8); // 0 ~ 7
Debug.Log($"<color=yellow>{itemNames[idx]}</color>");
_roulette.StartRotate(targetAngles[idx]);
});
}
}
'Study > 팁' 카테고리의 다른 글
[Tip] 맥 SVN 설치 - snailSVN (0) | 2024.07.21 |
---|---|
[Tip] 텍스트 코루틴 애니메이션 (0) | 2024.07.16 |
[Tip] Mathf.DeltaAngle (0) | 2024.06.29 |
[Tip] Object.FindObjectOfType (0) | 2024.06.11 |
[Tip] RenderSettings (0) | 2024.06.05 |