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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Changing GUI and Sprite Color C# problems

Discussion in '2D' started by Zivisx, Nov 15, 2014.

  1. Zivisx

    Zivisx

    Joined:
    Nov 15, 2014
    Posts:
    3
    (I would have posted this as a question but it wont let me saying i need a tag and it wont let me enter a tag, I am glad that feature works so well....)
    The current code i have is set up to change a sprite on a game object in addition it is also is suppose to change a GUI element to allow the player to have some feedback on what color is changing to. I used this on another sprite that works fine (The sprite changes color when i have it selected) however it is no longer allowing me to change the sprite color or the GUI color in any way except by specifically stating a color such as Color.Red.

    It is allowing me to change the Alpha just not the colors. It is incredibly frustrating because the code is fine it just wont work!



    // This Works
    transform.Find("SpriteOne").GetComponent<SpriteRenderer>().color = new Color (50,50,1,1);

    // This Does NOT Work!!
    transform.Find ("SpriteTwo").GetComponent<SpriteRenderer> ().color = new Color (50,50,1,1);

    // This Works
    transform.Find ("SpriteTwo").GetComponent<SpriteRenderer> ().color = Color.Red;

    // This Works
    GUI.color = Color.Red;

    // This Does NOT Work!!
    GUI.color = new Color (50,50,1,1);
     
  2. Zivisx

    Zivisx

    Joined:
    Nov 15, 2014
    Posts:
    3
    I figured it out, I didn't realize Unity automatically multiplies your floats by 255 so any number past 1 was considered maximum value for that color.
     
  3. GamerYou

    GamerYou

    Joined:
    Jun 13, 2013
    Posts:
    19
  4. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250