简体   繁体   English

鼠标单击对象统一5.3 UI?

[英]Mouse click object unity 5.3 UI?

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? 我应该如何格式化代码,以便每次单击对象GUI时出现? I'm currently using Unity version 5.3. 我目前正在使用Unity版本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. GUI元素绘制在OnGUI()函数内部。 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); 从Unity 5开始,您可以仅添加UI文本元素(rightclick hierarchy > UI > Text)或使用3D Text ,然后添加gameObject.SetActive(true/false); on that text when you run the OnMouseDown/Up() functions. 当您运行OnMouseDown/Up()函数时,会在该文本上显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM