0

我有 4 个按钮,按下按钮时每个按钮都会闪烁。但是,如果您要按下一个按钮,则当该按钮较暗(闪烁)时单击另一个按钮,该按钮将保持黑暗。我想在禁用它们之前重置精灵的颜色,但是它不起作用。按下按钮时,它们不再闪烁......

这是代码:

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");
        }
    }
4

1 回答 1

0

你可以写:

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;
于 2015-09-16T21:17:02.210 回答