Advertisement
Berenger

Pour Diana

Jul 21st, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. var movement : float = 1.0;
  4. var rotation : float = 30.0;
  5.  
  6. private var currSelection : Transform;
  7.  
  8. function Update ()
  9. {
  10.     // Picking
  11.     var info : RaycastHit;
  12.     var ray : Ray = Camera.main.ScreenPointToRay( Input.mousePosition );
  13.     if( Input.GetMouseButtonUp(0) )
  14.     {
  15.         CancelSelection();
  16.        
  17.         if( Physics.Raycast( ray, info ) )
  18.             Select( info.collider.gameObject );
  19.     }
  20.    
  21.     // Mettre le déplacement ici remet un peu en question le nom de "Selectionneur" pour le script mais bon ...
  22.     if( currSelection != null )
  23.     {
  24.         if( Input.GetKeyUp( KeyCode.Keypad4 ) ) currSelection.Translate( Vector3.left * movement );
  25.         if( Input.GetKeyUp( KeyCode.Keypad6 ) ) currSelection.Translate( Vector3.right * movement );
  26.         if( Input.GetKeyUp( KeyCode.Keypad8 ) ) currSelection.Translate( Vector3.forward * movement );
  27.         if( Input.GetKeyUp( KeyCode.Keypad2 ) ) currSelection.Translate( Vector3.back * movement );
  28.         if( Input.GetKeyUp( KeyCode.KeypadPlus ) ) currSelection.Translate( Vector3.up * movement );
  29.         if( Input.GetKeyUp( KeyCode.KeypadMinus ) )  currSelection.Translate( Vector3.down * movement );
  30.                                                                                              
  31.         if( Input.GetKeyUp( KeyCode.Keypad7 ) ) currSelection.Rotate( Vector3.up * -rotation );      
  32.         if( Input.GetKeyUp( KeyCode.Keypad9 ) ) currSelection.Rotate( Vector3.up * rotation );
  33.        
  34.         if( Input.GetKeyUp( KeyCode.Delete ) ) Destroy( currSelection.gameObject );
  35.     }
  36. }
  37.  
  38. function CancelSelection()
  39. {
  40.     if( currSelection != null )
  41.     {
  42.         print( "Lose selection " + currSelection );
  43.         currSelection.renderer.material.color = Color.white;
  44.         currSelection = null;
  45.     }
  46. }
  47.  
  48. function Select( newObj : GameObject )
  49. {
  50.     currSelection = newObj.transform;
  51.     currSelection.renderer.material.color = Color.red;
  52.     print( "New selection " + currSelection );
  53. }
  54.  
  55. function OnGUI()
  56. {
  57.     if( currSelection != null )
  58.     {
  59.         GUI.Label( Rect( Screen.width - 250, 10, 240, 100 ), "Pour bouger la séléction, utilise les touches dirrectionelles. Pour le tourner, utilise + et -." );
  60.         if( GUI.Button( Rect( 10, 30, 100, 20 ), "Reset" ) )
  61.         {
  62.             currSelection.position = Vector3.zero;
  63.             currSelection.rotation = Quaternion.identity;
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement