Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Sprite checker?

Discussion in 'Scripting' started by Huxz111222, Nov 14, 2019.

  1. Huxz111222

    Huxz111222

    Joined:
    Nov 14, 2019
    Posts:
    3
    I am trying to make a slot machine in Unity right now, and i have come to a stop. I have figured out how to randomize the sprites, but i cant seem to figure out, how to make you "win" like make a script that checks if three identical sprites are next to each other, is there a way to do that or is it impossible.
    Mind you i am VERY new to coding, so if you would like to help me please explain why or why it isn't possible;)
     
  2. Mokzen

    Mokzen

    Joined:
    Oct 10, 2016
    Posts:
    102
    I would make it so that the game didn't actually check the sprite, but the "state" of each "slot". The sprite would just be for show, but the real logic would assess the state of each slot, be it a numerical value comparison, or some other comparison.

    That would probably be a bit easier, depending on your setup.
     
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,386
    How do you select which sprite to display now? If you can choose a sprite, then you should be able to identify it as well by the same logic.
     
    Dextozz likes this.
  4. Huxz111222

    Huxz111222

    Joined:
    Nov 14, 2019
    Posts:
    3
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Symbol_Spawner : MonoBehaviour
    6.  
    7.  
    8. {
    9.     private int rand;
    10.     public Sprite[] Sprite_Pic;
    11.  
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         Change();
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.         if (transform.position.z == (-16))
    22.         {
    23.             Change();
    24.         }
    25.     }
    26.  
    27.     void Change()
    28.     {
    29.         rand = Random.Range(0, Sprite_Pic.Length);
    30.         GetComponent<SpriteRenderer>().sprite = Sprite_Pic[rand];
    31.  
    32.     }
    33. }
    And then i set the 8 different sprites
     
  5. Huxz111222

    Huxz111222

    Joined:
    Nov 14, 2019
    Posts:
    3
    So giving my gameobjects a value, and then making a script checking what value it is?