Question by
Pedro Garcia-Huidobro · Mar 28, 2016 at 09:34 PM ·
uicollider
How to have multiple colliders refer to different UI text?
Im trying to have UI text apear when the player enters a collider. Looking around i found this nice C# script from a tutorial ( here https://www.youtube.com/watch?v=D6ggcMdm9_4)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class fadeEffects : MonoBehaviour {
public Text _eventText;
public float fadeSpeed = 5f;
public bool entrance;
public GameObject _canvasAreal;
void Awake ()
{
_eventText = _canvasAreal.GetComponentInChildren<Text> ();
_eventText.color = Color.clear;
}
void Update ()
{
ColorChange();
}
void OnTriggerEnter (Collider col)
{
if (col.gameObject.tag == "Player")
{
entrance = true;
}
}
void OnTriggerExit (Collider col)
{
if (col.gameObject.tag == "Player")
{
entrance = false;
}
}
void ColorChange ()
{
if (entrance)
{
_eventText.color = Color.Lerp (_eventText.color, Color.black, fadeSpeed * Time.deltaTime);
}
if (!entrance)
{
_eventText.color = Color.Lerp (_eventText.color, Color.clear, fadeSpeed * Time.deltaTime);
}
}
}
but every time I enter play mode all the colliders refer to only one UI text. I have been trying different solutions but I simple have no idea how to make so every collider refers to only one UI text
How can I do that ?
Thanks for your time : )
Comment
Your answer