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

Set Opacity of text

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

  1. Jay2001

    Jay2001

    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,332
    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. Jay2001

    Jay2001

    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,332
    UnityEngine.UI.Text

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