I'm currently working on a project that is due Monday for school. I've been working on it for a while, but when it comes to coding I always unable to solve any errors since I'm practically a beginner. How should I format my code so every time I click an object GUI appears? I'm currently using Unity version 5.3.
Code:
#pragma strict
var scanners : UIText //variable for GUI text
function Start () //scanner not clicked
{
scanners.enabled=false;
}
function OnMouseDown() //scanner clicked
{
scanners.enabled=true;
}
function OnMouseUp() //scanner unclicked
{
scanners.enabled=false;
}
GUI elements are drawn inside the OnGUI() function. but this is an old way of doing things. Since Unity 5 you can just add a UI text element (rightclick hierarchy > UI > Text)
or use the 3D Text
, and then gameObject.SetActive(true/false);
on that text when you run the OnMouseDown/Up()
functions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.