显示不同的按钮点击不同的文本,我使用统一地方,有按钮,表示各种产品和产品名称是低于其他被显示在系统的顺序一个使用户交互式选择系统时,用户点击在产品上。我已经使用OnGUI()函数显示产品名称。但是在我的输出中,所有的名字都被印刷得超级强烈。团结
我绑使用静态变量i(最初定义为0)递增GUI.label的y位置。我尝试在每次点击时增加i的值,并将其添加到GUI.label的y位置。现在当我点击第二个按钮时,第一个按钮标签和第二个按钮标签都会移动到新的坐标系。
using UnityEngine;
using UnityEngine.EventSystems;// 1
using UnityEngine.UI;
``public class Example : MonoBehaviour, IPointerClickHandler // 2
// ... And many more available!
{
SpriteRenderer sprite;
Color target = Color.red;
int a=200,b=100;
public GUIText textObject;
public bool showGUI;
public int s=0;
public static int i=0;
void Awake()
{
sprite = GetComponent<SpriteRenderer>();
}
void test()
{
i = i + 20;
OnGUI();
}
void Update()
{
if (sprite)
sprite.color = Vector4.MoveTowards(sprite.color, target, Time.deltaTime * 10);
}
public void OnPointerClick(PointerEventData eventData) // 3
{
showGUI = true;
Debug.Log(gameObject.name);
target = Color.blue;
PlayerPrefs.SetString ("Display", gameObject.name);
s = 1;
test();
}
void OnGUI()
{
if (s == 1) {
GUI.color = Color.red;
GUIStyle myStyle = new GUIStyle (GUI.skin.GetStyle ("label"));
myStyle.fontSize = 20;
GUI.Label (new Rect (a, b, 100f, 10f), "");
if (showGUI) {
//GUI.Box (new Rect (a,b+i, 300f, 100f), "");
GUI.Label (new Rect (a, b + i, 300f, 100f), gameObject.name, myStyle);
s = 0;
}
}
}
}
太感谢你了!肯定会试试这个 –