dimanche 4 avril 2021

Simple 2d program working with colors, buttons, and if statements

I have another question again. I'm currently working on a game's major feature. Nothing too big, just a project for stuff. Anyhow the feature is like this: There are 3 buttons present. Clicking a button will change its color. The task here is to match every color of the buttons to a shade of green. Now, I have the buttons programmed to cycle through 4 colors, the same palette. It works, of course. What I want to implement now is, to make a text appear once all the buttons match colors. I'm working on Unity and the c# script is on Visual Studio. Below is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;



 public class ChangeColor : MonoBehaviour
    {
        [SerializeField] int count = 0;
        [SerializeField] Color[] colorArray;
       public void button ()
        {
            if(count < colorArray.Length)
            {
                gameObject.GetComponent<Image>().color = new Color(colorArray[count].r, colorArray[count].g, colorArray[count].b);
                if(count == colorArray.Length - 1)
                {
                    count = -1;
                }
                count += 1;
            }
            
        }
    }

Aucun commentaire:

Enregistrer un commentaire