Search Unity

Set Opacity of text

Discussion in 'UGUI & TextMesh Pro' started by WintermuteDigital, Jan 1, 2015.

  1. WintermuteDigital

    WintermuteDigital

    Joined:
    Dec 4, 2014
    Posts:
    19
    How do I have a script set the opacity of the text?
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Visiblity : MonoBehaviour
    5. {
    6.    
    7.     public GameObject UIText;
    8.        
    9.         void OnTriggerStay2D (Collider2D other)
    10.     {
    11.  
    12.         if (other.gameObject.tag == "Player")
    13.         {
    14.             Debug.Log ("Hi!");
    15.         }
    16.     }
    17. }    
    I want to replace the Debug.Log to make the public gameobject variable called UIText with an opacity of 255. How do I LERP two UI Text colours? I don't think that this is that hard to answer. Probably an easy solution. But, being a n00b, I don't get it. Help! Thanks!
     
  2. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    If you store a reference to the Text component then you can set the color property directly after using Color.Lerp. In your example you're storing the GameObject which isn't so useful on its own.
     
  3. WintermuteDigital

    WintermuteDigital

    Joined:
    Dec 4, 2014
    Posts:
    19
    Ok,but how do I do that? Public Text.UI?
     
  4. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    UnityEngine.UI.Text

    You can also use the UnityEngine.UI namespace to save typing.