Guest User

Untitled

a guest
Jan 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1.  
  2. // default vars
  3. var playerSpeed : int;
  4. var playerLives : int;
  5. var startDrag : Vector3;
  6. var endDrag : Vector3;
  7. var totalDrag : int;
  8.  
  9. var shipLocalPosition : Vector3;
  10. var shipStartTime : float;
  11.  
  12. var moving : boolean;
  13.  
  14. static var playerScore : int;
  15.  
  16. var bullet : Rigidbody;
  17.  
  18. function Update ()
  19. {
  20.  
  21. // get drag coords
  22. if (Input.GetButtonDown ("Fire1")) {
  23. startDrag = Input.mousePosition;
  24. }
  25. if (Input.GetButtonUp ("Fire1")) {
  26. endDrag = Input.mousePosition;
  27. shipStartTime = Time.time;
  28. moving = true;
  29. dragAmt = (endDrag.x - startDrag.x);
  30. }
  31.  
  32. // calculate drag
  33. if (moving)
  34. {
  35. dragMove();
  36. }
  37.  
  38. // amount to move player
  39. amtToMove = (playerSpeed * Input.GetAxis("Horizontal")) * Time.deltaTime;
  40.  
  41. // move / translate player
  42. transform.Translate(Vector3.right * amtToMove);
  43.  
  44. if(Input.GetKeyDown("space"))
  45. {
  46. var tempBullet : Rigidbody;
  47.  
  48. tempBullet = Instantiate(bullet, transform.position, transform.rotation);
  49. }
  50.  
  51. }
  52.  
  53. function OnGUI()
  54. {
  55. GUI.Label(Rect(10,10,200,50), "Score: " + playerScore);
  56. GUI.Label(Rect(10,30,200,50), "Lives: " + playerLives);
  57. GUI.Label(Rect(10,50,200,50), "StartDrag: " + startDrag.x);
  58. GUI.Label(Rect(10,70,200,50), "EndDrag: " + endDrag.x);
  59. }
  60.  
  61. function dragMove()
  62. {
  63. float animationTime = (Time.time - shipStartTime);
  64. float animationDuration = 2.0;
  65. transform.position = Vector3.Lerp(shipLocalPosition,shipLocalPosition + Vector3(2,0,0), animationTime / animationDuration );
  66.  
  67. if (animationTime > animationDuration)
  68. {
  69. moving = false;
  70. }
  71. }
Add Comment
Please, Sign In to add comment