- Home /
 
               Question by 
               youngapprentice · Aug 01, 2012 at 02:33 AM · 
                guitexturebuttonplane  
              
 
              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
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by youngapprentice · Aug 01, 2012 at 08:02 PM
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;
  }
  }
  
  
Answer by reptilebeats · Aug 01, 2012 at 03:18 AM
look up ray casting, http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                