Question by
stephanlevin · Jul 14, 2017 at 09:35 AM ·
c#scripting problemscripting beginnerscritping
use MouseOnClick two times?
Hey guys! I found this script called "DisplayUI". I want that it shows the information whenever I click on an object - when I click on it again it should disappear. Here's the code (c#): using UnityEngine; using UnityEngine.UI; using System.Collections;
public class displayUI : MonoBehaviour {
public string myString;
public Text myText;
public float fadeTime;
public bool displayInfo;
public float lifeSpan = 5;
// Use this for initialization
void Start() {
myText = GameObject.Find("Text").GetComponent<Text>();
myText.color = Color.clear;
//Screen.showCursor = false;
//Screen.lockCursor = true;
}
// Update is called once per frame
void Update()
{
FadeText();
/*if (Input.GetKeyDown (KeyCode.Escape))
{
Screen.lookCursor = false;
{
*/
}
void OnMouseEnter()
{
displayInfo = true;
lifeSpan = 2;
}
void OnMouseExit()
{
displayInfo = false;
lifeSpan = 2;
}
void FadeText()
{
if (displayInfo)
{
myText.text = myString;
myText.color = Color.Lerp(myText.color, Color.white, fadeTime * Time.deltaTime);
lifeSpan = 2;
}
else
{
myText.color = Color.Lerp(myText.color, Color.clear, fadeTime * Time.deltaTime);
lifeSpan = 2;
}
}
}
How could I do this?
Comment
Answer by NorthStar79 · Jul 15, 2017 at 02:52 PM
bool doTheThing=false;
void Update()
{
if(Input.GetMouseButtonDown(0))
doTheThing = !doTheThing;
if(doTheThing) YourUIpanel.SetActive(true);
Else YourUIpanel.SetActive(false);
}
thank you!! could you maybe give me the full script? like with everything i need in it? because i have no experience with c# and i don't really know how to put this script in my script
Your answer
Follow this Question
Related Questions
hide object with mouse enter 0 Answers
script an delay 0 Answers
Why won't my model rotate up on X axis? 1 Answer
OnTriggerExit does not work 0 Answers