Guest User

Untitled

a guest
Jan 21st, 2018
70
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. static var playerScore : int;
  13.  
  14. var bullet : Rigidbody;
  15.  
  16. function Update ()
  17. {
  18.  
  19. // get drag coords
  20. if (Input.GetButtonDown ("Fire1")) {
  21. endDrag.x = 0;
  22. startDrag = Input.mousePosition;
  23. }
  24. if (Input.GetButtonUp ("Fire1")) {
  25. endDrag = Input.mousePosition;
  26. }
  27.  
  28. // calculate drag
  29. if (startDrag.x != 0 && endDrag.x != 0){
  30. dragAmt = (endDrag.x - startDrag.x);
  31. if(dragAmt > 0){
  32. totalDrag = dragAmt;
  33. // save state
  34. shipStartTime = Time.time;
  35. transform.position = shipLocalPosition;
  36. dragMove();
  37. }else{
  38. totalDrag = 0;
  39. }
  40. }
  41.  
  42. // amount to move player
  43. amtToMove = (playerSpeed * Input.GetAxis("Horizontal")) * Time.deltaTime;
  44.  
  45. // move / translate player
  46. transform.Translate(Vector3.right * amtToMove);
  47.  
  48. if(Input.GetKeyDown("space"))
  49. {
  50. var tempBullet : Rigidbody;
  51.  
  52. tempBullet = Instantiate(bullet, transform.position, transform.rotation);
  53. }
  54.  
  55. }
  56.  
  57. function OnGUI()
  58. {
  59. GUI.Label(Rect(10,10,200,50), "Score: " + playerScore);
  60. GUI.Label(Rect(10,30,200,50), "Lives: " + playerLives);
  61. GUI.Label(Rect(10,50,200,50), "StartDrag: " + startDrag.x);
  62. GUI.Label(Rect(10,70,200,50), "EndDrag: " + endDrag.x);
  63. GUI.Label(Rect(10,90,200,50), "totalDrag: " + totalDrag);
  64. }
  65.  
  66. function dragMove()
  67. {
  68. transform.position = Vector3.Lerp(shipLocalPosition,shipLocalPosition + Vector3(2,0,0), ((Time.time - shipStartTime)/2));
  69. }
Add Comment
Please, Sign In to add comment