0

I have 4 buttons and they each flash when the button is pressed. However if you were to press a button, then while the button is darker (flashing) click another one, that button then stays dark. I want to reset the color of the sprite before disabling them however it's not working. When the buttons are pressed they no longer flash....

Here is the code:

void Start () {
        easy.GetComponent<SpriteRenderer>().color = color;
    }

    void Update () {
        if(difficultySelected[0] == true){
            enemyBehavior.shotsPerSecond = 0.2f;
            //Enabling the selected button
            easy.enabled = true;

            //Reseting the colors
            normal.GetComponent<SpriteRenderer>().color = color;
            hard.GetComponent<SpriteRenderer>().color = color;
            expert.GetComponent<SpriteRenderer>().color = color;

            //Disabling the 'unselected' buttons
            normal.enabled = false;
            hard.enabled = false;
            expert.enabled = false;

            easy.Play("Difficulty");
        }else if(difficultySelected[1] == true){
            enemyBehavior.shotsPerSecond = 0.5f;
            normal.enabled = true;

            easy.GetComponent<SpriteRenderer>().color = color;
            hard.GetComponent<SpriteRenderer>().color = color;
            expert.GetComponent<SpriteRenderer>().color = color;

            easy.enabled = false;
            hard.enabled = false;
            expert.enabled = false;

            normal.Play("Difficulty");
        }else if(difficultySelected[2] == true){
            enemyBehavior.shotsPerSecond = 1;
            hard.enabled = true;

            easy.GetComponent<SpriteRenderer>().color = color;
            normal.GetComponent<SpriteRenderer>().color = color;
            expert.GetComponent<SpriteRenderer>().color = color;

            easy.enabled = false;
            normal.enabled = false;
            expert.enabled = false;

            hard.Play("Difficulty");
        }else if(difficultySelected[3] == true){
            enemyBehavior.shotsPerSecond = 2;
            expert.enabled = true;

            easy.GetComponent<SpriteRenderer>().color = color;
            normal.GetComponent<SpriteRenderer>().color = color;
            hard.GetComponent<SpriteRenderer>().color = color;

            easy.enabled = false;
            normal.enabled = false;
            hard.enabled = false;

            expert.Play("Difficulty");
        }
    }
mr-matt
  • 218
  • 1
  • 8
  • 20
  • sounds like a Debugging task that you have ahead of yourself.. start debugging – MethodMan Sep 16 '15 at 19:18
  • I'm not that familiar with Unity3d, but alpha is generally a channel in color. `RGBA`.. I( think it's GBRA in 32bit targa files, but you generally don't have to deal with byte order in managed..) – Brett Caswell Sep 16 '15 at 19:20
  • masking is another technique that applies to the whole image/graphic/texture – Brett Caswell Sep 16 '15 at 19:21
  • at any rate.. I don't really see an SO question here necessarily, it seems more like a platform dependent question, and you'll probably get more info from http://gamedev.stackexchange.com/ on the matter. – Brett Caswell Sep 16 '15 at 19:24
  • Thanks guys! @BrettCaswell I have just put it up on gamedev.stackexchange.com – mr-matt Sep 16 '15 at 19:43

1 Answers1

0

You can write:

color.a = 1f; // value between 0 and 1, where 1 is opaque

//Resetting the colors
normal.GetComponent<SpriteRenderer>().color = color;
hard.GetComponent<SpriteRenderer>().color = color;
expert.GetComponent<SpriteRenderer>().color = color;
user3071284
  • 6,955
  • 6
  • 43
  • 57