using UnityEngine; using System.Collections; 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 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]; SetSpriteSize(); StartCoroutine(SpinSlots()); } public void SetSpinDuration(float duration) { spinDuration = duration; } public void SetSpriteSize() { foreach (SpriteRenderer renderer in slotRenderers) { renderer.transform.localScale = new Vector3(spriteSize.x, spriteSize.y, 1); } } public void AddSlotResult(int index, int value) { if(index >= 0 && index < slotIcons.Length) { results[index] = value; } } private IEnumerator SpinSlots() { float timeElapsed = 0; while(timeElapsed < spinDuration) { for(int i = 0; i < slotRenderers.Length; i++) { slotRenderers[i].sprite = slotIcons[Random.Range(0, slotIcons.Length)]; } timeElapsed += Time.deltaTime; yield return new WaitForSeconds(0.1f); // Adjust the interval for smoother animation } CalculateScore(); } private void CalculateScore() { int totalScore = 0; for(int i = 0; i < slotRenderers.Length; i++) { for(int j = 0; j < slotIcons.Length; j++) { if(slotRenderers[i].sprite == slotIcons[j]) { totalScore += results[j]; } } } // Implement score calculation based on single, double, and treble results int singleScore = 0, doubleScore = 0, trebleScore = 0; foreach(int result in results) { if(result == 1) singleScore++; else if(result == 2) doubleScore++; else if(result == 3) trebleScore++; } totalScore += singleScore + (doubleScore * 2) + (trebleScore * 3); Debug.Log("Total Score: " + totalScore); } }