Question by
stephanlevin · Jul 21, 2017 at 07:09 AM ·
c#scripting problemscripting beginnerscritping
hide object with mouse enter
hey guys! i have some cubes in my scene and i want that whenever i mouse enter one object it shows an arrow above the object (so you know which one is selected). i found a script which works like that but for texts...i tried to script kind of the same to show the arrows but it isn't working for multiple objects. could someone please help me? here's the script:`using UnityEngine; using UnityEngine.UI; using System.Collections;
public class displayUI : MonoBehaviour {
public string myString;
public Text myText;
public Object myObject;
public float fadeTime;
public bool displayInfo;
// Use this for initialization
void Start()
{
Object.FindObjectOfType<Renderer>().enabled = false;
myText.color = Color.clear;
//Screen.showCursor = false;
//Screen.lockCursor = true;
}
// Update is called once per frame
void Update()
{
FadeText();
}
void OnMouseOver()
{
displayInfo = true;
Object.FindObjectOfType<Renderer>().enabled = true;
}
void OnMouseExit()
{
displayInfo = false;
Object.FindObjectOfType<Renderer>().enabled = false;
}
void FadeText()
{
if (displayInfo)
{
myText.text = myString;
myText.color = Color.Lerp(myText.color, Color.white, fadeTime * Time.deltaTime);
}
else
{
myText.color = Color.Lerp(myText.color, Color.clear, fadeTime * Time.deltaTime);
}
}
Comment