unity-game-enginengui

Changing the UISprite tint color during runtime with NGUI not working


I have following code try to change to tint color of a UISprite to indicts an error, I could see the tint color has been changed to red in the inspector, but sprite in the scene kept unchanged, What Have I done wrong?

 private void ShowErr(string errMsg)
    {
        gameObject.GetComponent<UIWidget>().color = Color.red;
        //gameObject.GetComponent<UISprite>().color = Color.green;
        transform.GetChild(0).gameObject.SetActive(true);
        transform.GetChild(0).GetChild(0).GetComponent<UILabel>().text = errMsg;
    }

enter image description here

Following was the screenshot of the play scene, note that the sprite(which is the dashed border) kept the origin color but not red as expected.

enter image description here

Have tried to change the color with UIWidget and UISprite both works with the inspector but not the game scene.


Solution

  • Edit your sprite to be white instead of black, then you could set color.