Advertisement
Guest User

Roulette

a guest
Dec 9th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using System.Collections;
  5.  
  6. public class Roulette : MonoBehaviour
  7. {
  8.     public float RotationSpeed;
  9.  
  10.     public float MinAngle;
  11.     public float MaxAngle;
  12.  
  13.     public int CellsNumber;
  14.  
  15.     private float bet;
  16.     private CellType chosenCellType;
  17.  
  18.     private float cellAngle;
  19.  
  20.     private bool isRotating;
  21.  
  22.     [SerializeField] private Text OutputText;
  23.     [SerializeField] private InputField Input;
  24.     [SerializeField] private int[] CellsValue;
  25.  
  26.     private Transform trans;
  27.  
  28.     private void Start()
  29.     {
  30.         trans = GetComponent<Transform>();
  31.  
  32.         cellAngle = 360 / CellsNumber;
  33.     }
  34.  
  35.     public void StartRoulette(string cell)
  36.     {
  37.         bet = int.Parse(Input.text);
  38.         if (cell == "G") chosenCellType = CellType.Green;
  39.         else if (cell == "B") chosenCellType = CellType.Black;
  40.         else if (cell == "R") chosenCellType = CellType.Red;
  41.  
  42.         if (!isRotating && bet != 0)
  43.         {
  44.             GameManager.balance -= bet;
  45.  
  46.             StartCoroutine(Rotate());
  47.         }
  48.     }
  49.  
  50.     private void CheckAngle()
  51.     {
  52.         int finalCell = (int) trans.rotation.z / (int) cellAngle;
  53.  
  54.         if (finalCell == 0 && chosenCellType == CellType.Green)
  55.         {
  56.             Win(5);
  57.             return;
  58.         }
  59.         else if (finalCell % 2 != 0 && chosenCellType == CellType.Black)
  60.         {
  61.             Win(2);
  62.             return;
  63.         }
  64.         else if (finalCell % 2 == 0 && finalCell != 0 && chosenCellType == CellType.Red)
  65.         {
  66.             Win(2);
  67.             return;
  68.         }
  69.  
  70.         Loose();
  71.     }
  72.  
  73.     private void Loose()
  74.     {
  75.         OutputText.text = "Кандай жаман!";
  76.     }
  77.  
  78.     private void Win(int coeff)
  79.     {
  80.         GameManager.balance += bet * coeff;
  81.  
  82.         OutputText.text = "Оте жаксы!";
  83.     }
  84.  
  85.     private IEnumerator Rotate()
  86.     {
  87.         isRotating = true;
  88.  
  89.         //Вращение
  90.  
  91.         CheckAngle();
  92.  
  93.         isRotating = false;
  94.     }
  95.  
  96.     public enum CellType
  97.     {
  98.         Green,
  99.         Black,
  100.         Red
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement