Advertisement
irishstorm

CoordinatesDisplay.js

Dec 6th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //  CoordinatesDisplay.js
  2. //  Date : 04/12/2012
  3. //  Author : Christopher Cullen
  4.  
  5. //  Description :
  6. //  This script displays the objects coordinates on the screen in real-time
  7. //  and allows the user to reset the objects coordinates.
  8.  
  9. //  TODO:
  10. //  1)  Add a text field so that the user can set the xReset and yReset in realtime.
  11. //  2)  Make a default value for xReset and yReset, so if the object is out of bounds
  12. //      it will return to the default numvber stated.
  13.  
  14.  
  15.  
  16. //  Declares the Variable "yReset" as a type int with a value of "0".
  17. private var yReset : int = 0;
  18. //  Declares the Variable "xReset" as a type int with a value of "-6".
  19. private var xReset : int = -6;
  20.  
  21. //  I used these variables to position the GUI box,labal and buttons
  22. //  in realtime. Thought i would leave them in just to show my method.
  23. //  public var height : float;
  24. //  public var top : float;
  25.  
  26.  
  27. //  Function OnGUI
  28. //  This function displays the information to the user on the screen.
  29. //  The information the user will recive are as follows.
  30. //  1)  The X and Y coordinates.
  31. //  2)  Two buttons, so that the user can reset the position on X and Y axis.
  32.  
  33. function OnGUI()
  34. {
  35.     //  Stores transform.position.x and transform.position.y as a interger in the variables xPos and yPos.
  36.     var xPos : int = transform.position.x;
  37.     var yPos : int = transform.position.y;
  38.    
  39.     GUI.Box(Rect(5, 5, 180, 115), "Coordinates");
  40.     GUI.Label(Rect(10, 25, 180, 40), "X Position : " + xPos + " Y Position : " + yPos );
  41.    
  42.     if(GUI.Button(Rect(10, 50, 170, 30), "Reset X Position"))
  43.     {
  44.         transform.position.x = xReset;
  45.     }
  46.    
  47.     if(GUI.Button(Rect(10, 85, 170, 30), "Reset Y Position"))
  48.     {
  49.         transform.position.y = yReset;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement