using UnityEngine; public class SlotMachine : MonoBehaviour { // Enum to define the possible slot results public enum SlotResult { Attack, Dual, Slash } // Class to hold the reel information [System.Serializable] public class Reel { public SlotResult[] slotIcons; // Array to store the slot icons for the reel } public Reel[] reels; // Array to store all the reels public int[] reelValues; // Array to store the values of the slot results public int spinDuration = 2; // Duration of the spin in seconds void Start() { // Initialize the reels with some example data reels = new Reel[3]; // Assuming you have 3 reels reelValues = new int[] { 10, 20, 30 }; // Assign values to Attack, Dual, and Slash for (int i = 0; i < reels.Length; i++) { reels[i] = new Reel(); reels[i].slotIcons = new SlotResult[] { SlotResult.Attack, SlotResult.Dual, SlotResult.Slash }; } // Example of how to spin the reels StartCoroutine(SpinReels()); } // Coroutine to spin the reels private IEnumerator SpinReels() { for (int i = 0; i < reels.Length; i++) { yield return StartCoroutine(SpinReel(i)); } // Check for matches after all reels have stopped CheckForMatches(); } // Coroutine to spin a single reel private IEnumerator SpinReel(int reelIndex) { float elapsedTime = 0; while (elapsedTime < spinDuration) { // Randomly select a slot icon for the reel int randomIndex = Random.Range(0, reels[reelIndex].slotIcons.Length); reels[reelIndex].slotIcons[randomIndex] = (SlotResult)randomIndex; elapsedTime += Time.deltaTime; yield return null; } } // Function to check for matches and calculate the score private void CheckForMatches() { int score = 0; int[] resultCounts = new int[reelValues.Length]; // Count the occurrences of each slot result foreach (var reel in reels) { foreach (var icon in reel.slotIcons) { resultCounts[(int)icon]++; } } // Calculate the score based on the counts for (int i = 0; i < resultCounts.Length; i++) { if (resultCounts[i] == 2) { score += reelValues[i] * 2; // Double score for doubles } else if (resultCounts[i] >= 3) { score += reelValues[i] * 3; // Triple score for trebles } else { score += reelValues[i]; // Regular score for singles } } Debug.Log("Total Score: " + score); } }