我花了最后一个小时试图找出如何制作它,所以如果我的 GUITexture 被点击,就会发生一些事情。我正在使用 UnityScript,我认为这应该可以,但事实并非如此。此脚本应用于 GUITexture 游戏对象。
function OnMouseDown()
{
print("Button Clicked");
}
我花了最后一个小时试图找出如何制作它,所以如果我的 GUITexture 被点击,就会发生一些事情。我正在使用 UnityScript,我认为这应该可以,但事实并非如此。此脚本应用于 GUITexture 游戏对象。
function OnMouseDown()
{
print("Button Clicked");
}
你不应该那样做。您可以简单地制作一个 GUI BUTTON 并将图像引用到它。像下面的代码。代码来自统一网站,我认为不需要解释:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Texture btnTexture;
void OnGUI() {
if (!btnTexture) {
Debug.LogError("Please assign a texture on the inspector");
return;
}
if (GUI.Button(new Rect(10, 10, 50, 50), btnTexture))
Debug.Log("Clicked the button with an image");
if (GUI.Button(new Rect(10, 70, 50, 30), "Click"))
Debug.Log("Clicked the button with text");
}
}