In unity3d i want to Display a text UI when my mouse Cursor on the cube. but I c
ID: 3579047 • Letter: I
Question
In unity3d i want to Display a text UI when my mouse Cursor on the cube. but I cannot see the text message. could you find why cannot see the text please? I already write mystring part.....
here is my C# Code
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class displayUI : MonoBehaviour
{
public string myString;
public Text myText;
public float fadeTime;
public bool displayInfo;
// Use this for initialization
void Start()
{
//Screen.lockCursor = false;
myText = GameObject.Find("Text").GetComponent<Text>();
myText.color = Color.clear;
}
// Update is called once per frame
void Update()
{
FadeText();
/*
if(Input.GetKeyDown(KeyCode.Escape))
{
Screen.lockCursor = false;
}*/
}
void OnMouseOver()
{
displayInfo = true;
}
void OnMouseExit()
{
displayInfo = false;
}
void FadeText()
{
if (displayInfo)
{
myText.text = myString;
myText.color = Color.Lerp(myText.color, Color.black, fadeTime * Time.deltaTime);
}
else
{
myText.color = Color.Lerp(myText.color, Color.clear, fadeTime * Time.deltaTime);
}
}
}
Explanation / Answer
check the value in myString
I hope there is the no value myString
It may problem in below code
if (displayInfo)
{
myText.text = myString;
myText.color = Color.Lerp(myText.color, Color.black, fadeTime * Time.deltaTime);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.