SHARE
TWEET

franktrog's code (Unity)

a guest Jun 29th, 2012 34 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @script ExecuteInEditMode()
  2.  
  3. var rotateObj:Transform; //This is the empty object. The object being rotated is parented to this object.
  4. private var focusTrigger = false;
  5. private var smooth: float = 2;
  6. var speed:float = 150;
  7.  
  8. var iDetails:Texture2D;
  9. var iDetailsOffset:Vector2;
  10. var iDetailStyle:GUIStyle;
  11. private var iDetailsB = false;
  12.  
  13. var iFocus:Texture2D;
  14. var iFocusOffset:Vector2;
  15. var iFocusStyle:GUIStyle;
  16. private var iFocusB = false;
  17.  
  18. var iFocusR:Texture2D;
  19. var iFocusROffset:Vector2;
  20. var iFocusRStyle:GUIStyle;
  21. private var iFocusRB = false;
  22.  
  23. var iFocusT:Texture2D;
  24. var iFocusTOffset:Vector2;
  25. var iFocusTStyle:GUIStyle;
  26. private var iFocusTB = false;
  27.  
  28. var iInfo:Texture2D;
  29. var iInfoOffset:Vector2;
  30. var iInfoStyle:GUIStyle;
  31. private var iInfoB = false;
  32.  
  33. var info:Texture2D;
  34. var infoOffset:Vector2;
  35. var infoStyle:GUIStyle;
  36. private var infoB = false;
  37.  
  38. function OnGUI() {    
  39.      iDetailsB = GUI.Button(Rect(iDetailsOffset.x,iDetailsOffset.y,iDetails.width,iDetails.height),"",iDetailStyle);    
  40.      iFocusB = GUI.Button(Rect(iFocusOffset.x,iFocusOffset.y,iFocus.width,iFocus.height),"",iFocusStyle);    
  41.      iFocusRB = GUI.Button(Rect(iFocusROffset.x,iFocusROffset.y,iFocusR.width,iFocusR.height),"",iFocusRStyle);    
  42.      iFocusTB = GUI.Button(Rect(iFocusTOffset.x,iFocusTOffset.y,iFocusT.width,iFocusT.height),"",iFocusTStyle);
  43.      iInfoB = GUI.Button(Rect(iInfoOffset.x,iInfoOffset.y,iInfo.width,iInfo.height),"",iInfoStyle);
  44.      infoB = GUI.Button(Rect(infoOffset.x,infoOffset.y,info.width,info.height),"",infoStyle);
  45. }
  46.  
  47.    
  48. function start(){
  49.     Camera.main.transform.LookAt(rotateObj);
  50. }
  51.  
  52.  
  53.     function Update(){
  54.        
  55.         if(iDetailsB){
  56.         }
  57.        
  58.         if(iFocusB){   
  59.         focusTrigger = true;
  60.         }
  61.        
  62.         if(focusTrigger == true){//Rotate the object to view it from a 3/4 view. Currently it isn't a smooth transition, just a quick jump.
  63.                                                          //Also focusTrigger never equals false even though the if statement it is part of triggers fine.
  64.                 rotateObj.transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.identity, Time.deltaTime*smooth);;
  65.                 if(rotateObj.transform.rotation == Quaternion.identity) focusTrigger = false;
  66.         Camera.main.transform.LookAt(rotateObj);
  67.         }
  68.        
  69.         if(iFocusRB){//Rotate the object to view it from the right side. Currently it isn't a smooth transition, just a quick jump.
  70.                 rotateObj.transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(90, 0, 0), Time.deltaTime*smooth);;
  71.         Camera.main.transform.LookAt(rotateObj);
  72.         }
  73.        
  74.         if(iFocusTB){//Rotate the objec to view it from the top
  75.         }
  76.        
  77.         if(iInfoB){//Show info
  78.         }
  79.        
  80.         if(infoB){//More info
  81.         }      
  82.        
  83.         if(Input.GetMouseButton(0)){//Checks to see if the mouse is pressed and rotates the object accordingly. This code works!!!
  84.         rotateObj.transform.Rotate(Vector3(Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X")*-1, 0) * Time.deltaTime * speed);
  85.         Camera.main.transform.LookAt(rotateObj);
  86.         }
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top