Advertisement
Sabotender

Eirik GUI Texture Buttons

Feb 27th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class EirikGUI : MonoBehaviour {
  5.     public float offset;
  6.     public GUISkin skin;
  7.  
  8.     public Texture mainTex;
  9.     public Texture downTex;
  10.     public bool pushed;
  11.  
  12.     private Rect rect = new Rect(0,0,50,100);
  13.  
  14.     // Use this for initialization
  15.     void Update () {
  16.         //offset = 300 + (Mathf.Sin(Time.time * 3) * 30);
  17.         rect = new Rect(5 + offset,0, 50, 100);
  18.     }
  19.    
  20.     // Update is called once per frame
  21.     void OnGUI () {
  22.         GUI.skin = skin;
  23.  
  24.         GUILayout.BeginArea(rect);
  25.         GUILayout.Label("LOL");
  26.         if(GUILayout.Button("", (GUIStyle)"MyImgButton", GUILayout.Width(50), GUILayout.Height(50))) {
  27.             Debug.Log("POOSHED");
  28.         }
  29.  
  30.         GUILayout.EndArea();
  31.  
  32.         GUI.DrawTexture(rect, pushed ? downTex : mainTex);
  33.  
  34.         if(rect.Contains(Input.mousePosition)) {
  35.             if(Input.GetMouseButtonDown(0)) {
  36.                 pushed = true;
  37.             } else if(Input.GetMouseButtonUp() && pressed) {
  38.                 //do stuff
  39.                 pushed = false;
  40.             }
  41.         } else if(Input.GetMouseButtonUp(0)){
  42.             pushed = false;
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement