using System.Collections; using UnityEngine; using UnityEngine.UI; public class SlotMachine : MonoBehaviour { public enum SlotResult { Attack, Dual, Slash } [System.Serializable] public class Reel { public SlotResult[] slotIcons; } public Reel[] reels; public int[] reelValues; public int spinDuration = 2; public Image[] reelImages; // Array to store the UI images for the reels public Sprite[] slotSprites; // Array to store the sprites for the slot results public Text scoreText; // UI text to display the score void Start() { reels = new Reel[3]; reelValues = new int[] { 10, 20, 30 }; for (int i = 0; i < reels.Length; i++) { reels[i] = new Reel(); reels[i].slotIcons = new SlotResult[] { SlotResult.Attack, SlotResult.Dual, SlotResult.Slash }; } StartCoroutine(SpinReels()); } private IEnumerator SpinReels() { for (int i = 0; i < reels.Length; i++) { yield return StartCoroutine(SpinReel(i)); } CheckForMatches(); } private IEnumerator SpinReel(int reelIndex) { float elapsedTime = 0; while (elapsedTime < spinDuration) { int randomIndex = Random.Range(0, reels[reelIndex].slotIcons.Length); reels[reelIndex].slotIcons[randomIndex] = (SlotResult)randomIndex; reelImages[reelIndex].sprite = slotSprites[randomIndex]; // Update the UI image elapsedTime += Time.deltaTime; yield return null; } } private void CheckForMatches() { int score = 0; int[] resultCounts = new int[reelValues.Length]; foreach (var reel in reels) { foreach (var icon in reel.slotIcons) { resultCounts[(int)icon]++; } } for (int i = 0; i < resultCounts.Length; i++) { if (resultCounts[i] == 2) { score += reelValues[i] * 2; } else if (resultCounts[i] >= 3) { score += reelValues[i] * 3; } else { score += reelValues[i]; } } scoreText.text = "Total Score: " + score; // Update the score display Debug.Log("Total Score: " + score); } }