Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- var movement : float = 1.0;
- var rotation : float = 30.0;
- private var currSelection : Transform;
- function Update ()
- {
- // Picking
- var info : RaycastHit;
- var ray : Ray = Camera.main.ScreenPointToRay( Input.mousePosition );
- if( Input.GetMouseButtonUp(0) )
- {
- CancelSelection();
- if( Physics.Raycast( ray, info ) )
- Select( info.collider.gameObject );
- }
- // Mettre le déplacement ici remet un peu en question le nom de "Selectionneur" pour le script mais bon ...
- if( currSelection != null )
- {
- if( Input.GetKeyUp( KeyCode.Keypad4 ) ) currSelection.Translate( Vector3.left * movement );
- if( Input.GetKeyUp( KeyCode.Keypad6 ) ) currSelection.Translate( Vector3.right * movement );
- if( Input.GetKeyUp( KeyCode.Keypad8 ) ) currSelection.Translate( Vector3.forward * movement );
- if( Input.GetKeyUp( KeyCode.Keypad2 ) ) currSelection.Translate( Vector3.back * movement );
- if( Input.GetKeyUp( KeyCode.KeypadPlus ) ) currSelection.Translate( Vector3.up * movement );
- if( Input.GetKeyUp( KeyCode.KeypadMinus ) ) currSelection.Translate( Vector3.down * movement );
- if( Input.GetKeyUp( KeyCode.Keypad7 ) ) currSelection.Rotate( Vector3.up * -rotation );
- if( Input.GetKeyUp( KeyCode.Keypad9 ) ) currSelection.Rotate( Vector3.up * rotation );
- if( Input.GetKeyUp( KeyCode.Delete ) ) Destroy( currSelection.gameObject );
- }
- }
- function CancelSelection()
- {
- if( currSelection != null )
- {
- print( "Lose selection " + currSelection );
- currSelection.renderer.material.color = Color.white;
- currSelection = null;
- }
- }
- function Select( newObj : GameObject )
- {
- currSelection = newObj.transform;
- currSelection.renderer.material.color = Color.red;
- print( "New selection " + currSelection );
- }
- function OnGUI()
- {
- if( currSelection != null )
- {
- GUI.Label( Rect( Screen.width - 250, 10, 240, 100 ), "Pour bouger la séléction, utilise les touches dirrectionelles. Pour le tourner, utilise + et -." );
- if( GUI.Button( Rect( 10, 30, 100, 20 ), "Reset" ) )
- {
- currSelection.position = Vector3.zero;
- currSelection.rotation = Quaternion.identity;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement