【发布时间】:2014-06-02 11:25:07
【问题描述】:
我目前有一些代码可以通过数组在屏幕上放置一些按钮,并在检查器中分配纹理。问题是我不知道如何让按钮 1 退出游戏,按钮 2 进入下一个级别,按钮 3 加载图像。有人可以向我解释我需要做什么才能使单个按钮在单击时执行不同的操作吗? (第二个数组是我屏幕右侧的按钮)
这就是我的代码现在的样子:
using UnityEngine;
using System.Collections;
public class UI : MonoBehaviour
{
public Texture2D[] parts;
public Texture2D[] extra;
int buttonHeight, buttonWidth;
int x, y;
int width, height;
void OnGUI ()
{
for (int i = 0; i < parts.Length; ++i)
{
if (GUI.Button (new Rect (x - 35, i * (height + 97), width + 300, height + 90), parts [i]))
Debug.Log ("Clicked button " + i);
//if (GUI.Button (new Rect (0, i * (buttonHeight + 20), buttonWidth + 100, buttonHeight + 100), textures [i]))
}
for (int x = 0; x < extra.Length; ++x)
{
if (GUI.Button (new Rect (x + 800, x * (height + 140), width + 300, height + 120), extra [x]))
Debug.Log ("Clicked button " + x);
if (extra [0] && Input.GetButtonDown ("Jump"))
{
Application.CaptureScreenshot ("Screenshot.png");
Debug.Log ("Screen captured");
}
}
}
}
【问题讨论】: