Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- using System.Collections;
- public class Roulette : MonoBehaviour
- {
- public float RotationSpeed;
- public float MinAngle;
- public float MaxAngle;
- public int CellsNumber;
- private float bet;
- private CellType chosenCellType;
- private float cellAngle;
- private bool isRotating;
- [SerializeField] private Text OutputText;
- [SerializeField] private InputField Input;
- [SerializeField] private int[] CellsValue;
- private Transform trans;
- private void Start()
- {
- trans = GetComponent<Transform>();
- cellAngle = 360 / CellsNumber;
- }
- public void StartRoulette(string cell)
- {
- bet = int.Parse(Input.text);
- if (cell == "G") chosenCellType = CellType.Green;
- else if (cell == "B") chosenCellType = CellType.Black;
- else if (cell == "R") chosenCellType = CellType.Red;
- if (!isRotating && bet != 0)
- {
- GameManager.balance -= bet;
- StartCoroutine(Rotate());
- }
- }
- private void CheckAngle()
- {
- int finalCell = (int) trans.rotation.z / (int) cellAngle;
- if (finalCell == 0 && chosenCellType == CellType.Green)
- {
- Win(5);
- return;
- }
- else if (finalCell % 2 != 0 && chosenCellType == CellType.Black)
- {
- Win(2);
- return;
- }
- else if (finalCell % 2 == 0 && finalCell != 0 && chosenCellType == CellType.Red)
- {
- Win(2);
- return;
- }
- Loose();
- }
- private void Loose()
- {
- OutputText.text = "Кандай жаман!";
- }
- private void Win(int coeff)
- {
- GameManager.balance += bet * coeff;
- OutputText.text = "Оте жаксы!";
- }
- private IEnumerator Rotate()
- {
- isRotating = true;
- //Вращение
- CheckAngle();
- isRotating = false;
- }
- public enum CellType
- {
- Green,
- Black,
- Red
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement