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

SetColor for UIText object

Discussion in 'General Graphics' started by Jay2001, Jan 1, 2015.

  1. Jay2001

    Jay2001

    Joined:
    Dec 4, 2014
    Posts:
    19
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Visiblity : MonoBehaviour
    5. {
    6.     public GUIText Text;
    7.     void OnTriggerStay2D (Collider2D other)
    8.     {
    9.  
    10.         if (other.gameObject.tag == "Player")
    11.         {
    12.             Text.material.SetColor( Color.black);
    13.         }
    14.     }
    15. }    
    How do I use the SetColor argument(I think it's an argument) to change the color? I get this error:
    error CS1501: No overload for method `SetColor' takes `1' arguments
    Thanks in advance.
     
  2. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,121
    Check out the documentation. That function needs to know which color field you would like to editor on the material. So, for the main color, you can use "_Color".

    Code (CSharp):
    1. Text.material.SetColor( "_Color", Color.black);
    Or set the color directly using the color property

    Code (CSharp):
    1. Text.material.color = Color.black;
     
  3. Jay2001

    Jay2001

    Joined:
    Dec 4, 2014
    Posts:
    19
    Thanks so much guys! You're really helpful. Good to know there are nice people here.
     
    Prodigga likes this.