Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CoordinatesDisplay.js
- // Date : 04/12/2012
- // Author : Christopher Cullen
- // Description :
- // This script displays the objects coordinates on the screen in real-time
- // and allows the user to reset the objects coordinates.
- // TODO:
- // 1) Add a text field so that the user can set the xReset and yReset in realtime.
- // 2) Make a default value for xReset and yReset, so if the object is out of bounds
- // it will return to the default numvber stated.
- // Declares the Variable "yReset" as a type int with a value of "0".
- private var yReset : int = 0;
- // Declares the Variable "xReset" as a type int with a value of "-6".
- private var xReset : int = -6;
- // I used these variables to position the GUI box,labal and buttons
- // in realtime. Thought i would leave them in just to show my method.
- // public var height : float;
- // public var top : float;
- // Function OnGUI
- // This function displays the information to the user on the screen.
- // The information the user will recive are as follows.
- // 1) The X and Y coordinates.
- // 2) Two buttons, so that the user can reset the position on X and Y axis.
- function OnGUI()
- {
- // Stores transform.position.x and transform.position.y as a interger in the variables xPos and yPos.
- var xPos : int = transform.position.x;
- var yPos : int = transform.position.y;
- GUI.Box(Rect(5, 5, 180, 115), "Coordinates");
- GUI.Label(Rect(10, 25, 180, 40), "X Position : " + xPos + " Y Position : " + yPos );
- if(GUI.Button(Rect(10, 50, 170, 30), "Reset X Position"))
- {
- transform.position.x = xReset;
- }
- if(GUI.Button(Rect(10, 85, 170, 30), "Reset Y Position"))
- {
- transform.position.y = yReset;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement