Search Unity

Unity UI Fade In/out text after zooming.

Discussion in 'UGUI & TextMesh Pro' started by BramHamaekers, Mar 17, 2018.

  1. BramHamaekers

    BramHamaekers

    Joined:
    Mar 17, 2018
    Posts:
    1
    Hey there!

    I am currently trying to make a simulation of our solar system in Unity. Right now I am dealing with the nametags for the planets. I got the text to follow the planet!

    My question: Is it possible to make that text fade out when I zoom in close to my planet. And fade it in when I am far away.

    This is the code I currently have for the text:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class PlanetTag : MonoBehaviour
    7. {
    8.     public Text nameLable;
    9.  
    10.  
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.         Vector3 namePose = Camera.main.WorldToScreenPoint(this.transform.position);
    15.         nameLable.transform.position = namePose;
    16.     }
    17. }
    How would I go about implementing this fade system?
     
  2. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    I would approach this this the other way around. I would have a list/array of all of the planets, their names and positions, then I would find the planets on the list based on distance and use that list to show the names...

    There's a star map example somewhere, and if I find it, I'll post it.

    [edit]
    Found it:

    [/edit]
     
    Beks_Omega likes this.