Selection-Grid

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "Author: Bérenger == Description == makes a grid using a texture of your choice == Usage == get / make a texture representing your buttons. <syntaxhighlight lang="js"> //...")
 
Line 8: Line 8:
 
get / make a texture representing your buttons.
 
get / make a texture representing your buttons.
  
<syntaxhighlight lang="js">
+
<syntaxhighlight lang="javascript">
  
 
//this example uses a texture2d of x = 12 squares and y = 12 squares, i made the texture 360 but it turned to 240 in button so each button is 20 pixels.
 
//this example uses a texture2d of x = 12 squares and y = 12 squares, i made the texture 360 but it turned to 240 in button so each button is 20 pixels.

Revision as of 07:54, 9 June 2014

Author: Bérenger

Description

makes a grid using a texture of your choice

Usage

get / make a texture representing your buttons.

//this example uses a texture2d of x = 12 squares and y = 12 squares, i made the texture 360 but it turned to 240 in button so each button is 20 pixels.
 
var style1 : GUIStyle;//empty style to make no button borders.
function OnGUI(){
				var gridpixels = 20;//pixels per grid square
				var gidxsquares = 12;//num squares in x direction
				if (GUI.Button(Rect(320,10,240,60),fctbutton,style1))
		{
				var xpos = Input.mousePosition.x - 320 ;
				var ypos = Screen.height - Input.mousePosition.y -10;
 
				var result =  Mathf.Floor(xpos / gridpixels) + Mathf.Floor(ypos / gridpixels)*gidxsquares + 1;//plus 1 at end for not zero first square
				//
				print (result);
		}	
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox