If you have any questions let me know!
using UnityEngine;
using System.Collections;
public class mouse : MonoBehaviour {
//drag and drop images for buttons and Cursor into the inspector
public Texture2D curtex;
public Texture2D but;
public Texture2D butover;
float cx;
float cy;
float sx;
float sy;
public int speed;
int i;
Rect r;
Rect[] mybuttons;
string[] labels;
string display;
int buttonnow;
// Use this for initialization
void Start () {
display = "use arrows to move cursor and spacebar to push a button";
display = display + "
Replace cursor and button images in the inspector";
if (butover == null) {butover = new Texture2D (1, 1);
butover.SetPixel(0,0,Color.green);
butover.Apply();
}
if (but == null) {but = new Texture2D (1, 1);
but.SetPixel(0,0,Color.red);
but.Apply();
}
if (curtex == null) {curtex = new Texture2D (1, 1);}
mybuttons= new Rect[4];//<set number of buttons here
//set button coordinates and size by screen percentages below;
mybuttons [0] = new Rect (0.3f, 0.3f, 0.3f, 0.05f);
mybuttons [1] = new Rect (0.8f, 0.8f, 0.1f, 0.05f);
mybuttons [2] = new Rect (0.5f, 0.4f, 0.1f, 0.1f);
mybuttons [3] = new Rect (0.2f, 0.5f, 0.2f, 0.1f);
labels = new string[mybuttons.Length];
// set button labels here
labels [0] = "first";
labels [1] = "second";
labels [2] = "3";
labels [3] = "but 4";
if (speed == 0) {speed = 200;}
}
void OnGUI(){
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUI.skin.label.fontSize = 20;
GUI.Label(new Rect(0,0,sx,sy*0.2f),display);
i = mybuttons.Length;
while (i>0) {i--;
r=new Rect(mybuttons<em>.x*sx,mybuttons<em>.y*sy,mybuttons<em>.width*sx,mybuttons_.height*sy);_</em></em></em>
* if(i==buttonnow){GUI.DrawTexture (r, butover);}else{GUI.DrawTexture (r, but);}*
_ GUI.Label(r,labels*);
}*_
_ GUI.DrawTexture (new Rect (cx, cy, sx*0.03f, sy * 0.03f), curtex);_
* }*
* void Update () {*
* sx = Screen.width;*
* sy = Screen.height;*
_ if(Input.GetKey(“up”)){ cy-=Time.deltaTimespeed;}
if(Input.GetKey(“down”)){cy+=Time.deltaTimespeed;}_
_ if(Input.GetKey(“right”)){cx+=Time.deltaTimespeed;}
if(Input.GetKey(“left”)){cx-=Time.deltaTimespeed;}_
* buttonnow = -1;*
* i = mybuttons.Length;*
* while (i>0) {i–;*
r=new Rect(mybuttons.xsx,mybuttons.ysy,mybuttons.widthsx,mybuttons_.heightsy);
* if(cx>r.x){if(cx<r.x+r.width){
if(cy>r.y){if(cy<r.y+r.height){
buttonnow=i;}}}}*_
* }*
* if(Input.GetKeyDown(“space”)){if(buttonnow>-1){*
* display="I Pushed button number: "+buttonnow;*
* }}*
* }*
}