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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Sprite aplha

Discussion in 'UGUI & TextMesh Pro' started by LinMyLin, Nov 2, 2018.

  1. LinMyLin

    LinMyLin

    Joined:
    Mar 8, 2018
    Posts:
    10
    Hi!

    Code (CSharp):
    1. Color Sandra = IMG.GetComponent<Image>().color;
    2. Sandra.a = 0x00;
    3. IMG.GetComponent<Image>().color = Sandra;
    Its ok! Alpha = 0

    Code (CSharp):
    1. Color Sandra = IMG.GetComponent<Image>().color;
    2. Sandra.a = 0xC7;
    3. IMG.GetComponent<Image>().color = Sandra;
    Doesnt work, alpha = 255. I need 200. How to make alpha 200?
     
    Last edited: Nov 2, 2018
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    In code, color values use the range 0-1 instead of 0-255. You can find your color values by dividing the color value you want by the max value (255).

    200 / 255 = 0.784

    So this is the code you want:
    Sandra.a = 0.784f;
    or
    Sandra.a = 200f / 255f;
     
    LinMyLin likes this.
  3. LinMyLin

    LinMyLin

    Joined:
    Mar 8, 2018
    Posts:
    10
    Tnx