using UnityEngine; using System.Collections; using System.Collections.Generic; public class SlotMachine : MonoBehaviour { public Sprite[] slotIcons; // Array to hold slot icons public float spinDuration = 2.0f; // Duration of the spin public Vector2 spriteSize = new Vector2(1, 1); // Size of the slot icons public int[] slotValues; // Array to hold the values for each result private SpriteRenderer[] slotRenderers; // Array to hold SpriteRenderers private int[] results; // Array to hold the result values void Start() { slotRenderers = GetComponentsInChildren(); results = new int[slotRenderers.Length]; // Check if any SpriteRenderer components are found if (slotRenderers.Length == 0) { Debug.LogError("No SpriteRenderers found in children."); return; } SetSpriteSize(); // Start the spin coroutine StartCoroutine(SpinSlots()); } public void SetSpinDuration(float duration) { spinDuration = duration; } public void SetSpriteSize() { foreach (SpriteRenderer renderer in slotRenderers) { if (renderer != null) { renderer.transform.localScale = new Vector3(spriteSize.x, spriteSize.y, 1); } } } public void AddSlotResult(int index, int value) { if (index >= 0 && index < slotIcons.Length) { slotValues[index] = value; } } private IEnumerator SpinSlots() { float timeElapsed = 0; while (timeElapsed < spinDuration) { for (int i = 0; i < slotRenderers.Length; i++) { if (slotIcons.Length > 0) { slotRenderers[i].sprite = slotIcons[Random.Range(0, slotIcons.Length)]; } } timeElapsed += Time.deltaTime; yield return new WaitForSeconds(0.1f); // Smooth spinning animation } CalculateDamage(); } private void CalculateDamage() { int totalDamage = 0; // Get results for (int i = 0; i < slotRenderers.Length; i++) { for (int j = 0; j < slotIcons.Length; j++) { if (slotRenderers[i].sprite == slotIcons[j]) { results[i] = slotValues[j]; } } } // Implement damage calculation based on single, double, and treble results Dictionary resultCount = new Dictionary(); foreach (int result in results) { if (resultCount.ContainsKey(result)) { resultCount[result]++; } else { resultCount[result] = 1; } } foreach (KeyValuePair entry in resultCount) { if (entry.Value == 1) { totalDamage += entry.Key; } else if (entry.Value == 2) { totalDamage += entry.Key * 2; } else if (entry.Value == 3) { totalDamage += entry.Key * 3; } // Add more conditions if you add more reels }