1.找张按钮图片放在Assets目录下
2.新建个脚本并挂在主摄像机上
using UnityEngine;
using System.Collections;
public class ButtonTest : MonoBehaviour {
public Texture buttonTexture;
void OnGUI()
{
float scaleX = Screen.width / 640.0f; //横向放缩比
float scaleY = Screen.height / 960.0f; //纵向放缩比
//要绘制到的屏幕位置
Rect rect = new Rect(50 * scaleX, 50 * scaleY, 86 * scaleX, 26 * scaleY);
if (GUI.Button(rect, buttonTexture, new GUIStyle()))
{
Debug.Log("Button Click");
}
}
}
运行效果: