x


Make a Button out of a Textured Plane

How would I go about making a button out of a textured plane? (I just want basic feedback. Like how would I fetch the data for when: The mouse is over the button, is clicking the button, or the button has been clicked on)? Thanks!- YA

more ▼

asked Aug 01 '12 at 02:33 AM

youngapprentice gravatar image

youngapprentice
394 11 28 36

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I ended up using a simpler method. Here is my script:

    #pragma strict
//Setting the images for each of the 3 Button Stages
var NormTex : Texture2D;
var HighTex : Texture2D;
var DownTex : Texture2D;

// To check if the mouse is over the button
var over : boolean = false;

//Set it to normal on start
function Awake(){
 renderer.material.mainTexture = NormTex;
 }

/*If the mouse is over it, set the texture to highlighted
Note: To save CPU, it is "OnMouseEnter" as opposed to "OnMouseDown", which would be called
Every frame the mouse is over the plane.*/

function OnMouseEnter(){
 over = true;
 renderer.material.mainTexture = HighTex;
 }

// Changes back to normal on the exit

function OnMouseExit(){
 over = false;
 renderer.material.mainTexture = NormTex;
 }

// Changes to click graphic on click

function OnMouseDown(){
 renderer.material.mainTexture = DownTex;
 }

//Changes the button back based on wether or not the mouse is over it
//This may be unnecessary but eliminates the possibility of it being screwed up

function OnMouseUp(){
 if(over){
 renderer.material.mainTexture = HighTex;
 }else{
 renderer.material.mainTexture = NormTex;
 }
 }
more ▼

answered Aug 01 '12 at 08:02 PM

youngapprentice gravatar image

youngapprentice
394 11 28 36

(comments are locked)
10|3000 characters needed characters left
more ▼

answered Aug 01 '12 at 03:18 AM

reptilebeats gravatar image

reptilebeats
1.2k 57 108 137

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3815
x2279
x820
x266

asked: Aug 01 '12 at 02:33 AM

Seen: 549 times

Last Updated: Aug 01 '12 at 08:02 PM