Advertisement
Guest User

Main

a guest
Oct 31st, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. #pragma strict
  2. var Player : GameObject;
  3. var Gravity:float = 2;
  4. var speed:float = 2;
  5. var anim : Animator;
  6. var other : enemyprefabcode;
  7. var combo : int = 0;
  8. var GUIcombo : GUIText;
  9. var lives : int = 3;
  10. var GUIlives : GUIText;
  11. var jumped: boolean = false;
  12. var jumplevel2 = false;
  13. var jumplevel3 = false;
  14. var minSwipeDistY : float;
  15. var minSwipeDistX : float;
  16. var startPos :Vector2;
  17. //enemy1
  18. var Enemyprefab : GameObject;
  19. function Awake(){
  20. GUIcombo.text = "COMBO: ";
  21. GUIlives.text = "LIVES: 3";
  22. }
  23. function Start () {
  24. anim = GetComponent(Animator);
  25.  
  26. while (true) {
  27. yield WaitForSeconds (Random.Range(3, 0));
  28. var Enemyclone = Instantiate(Enemyprefab);
  29. }
  30. other = GameObject.FindWithTag("enemy").GetComponent("enemyprefabcode");
  31.  
  32. }
  33.  
  34. function Update () {
  35. if (lives <= 0){
  36. Destroy(Player);
  37. }
  38. Player.transform.position.x = -4.325;
  39. if (jumped == false){
  40. anim.SetFloat("hf",0.0);
  41. }
  42. if(Input.GetButtonDown("Fire1") && jumped==false){
  43. jumpup();
  44. jumped = true;
  45. }
  46. if(jumped==true){
  47. anim.SetFloat("hf",1);
  48. }
  49. if (Input.touchCount > 0)
  50. {
  51. var touch : Touch = Input.touches[0];
  52. switch (touch.phase)
  53. {
  54. case TouchPhase.Began:
  55. startPos = touch.position;
  56. break;
  57. case TouchPhase.Ended:
  58. var swipeDistVertical : float;
  59. swipeDistVertical = (new Vector3(0, touch.position.y, 0) - new Vector3(0, startPos.y, 0)).magnitude;
  60. if (swipeDistVertical > minSwipeDistY)
  61. {
  62. var swipeValue : float;
  63. swipeValue = Mathf.Sign(touch.position.y - startPos.y);
  64. if (swipeValue > 0)//up
  65. {
  66. glide();
  67. //Swipe.text = "Up Swipe";
  68. }
  69. else if (swipeValue < 0)//down
  70. {
  71. slam();
  72. //Swipe.text = "Down Swipe";
  73. }
  74. }
  75. var swipeDistHorizontal : float;
  76. swipeDistHorizontal = (new Vector3(touch.position.x,0, 0) - new Vector3(startPos.x, 0, 0)).magnitude;
  77. if (swipeDistHorizontal > minSwipeDistX)
  78. {
  79. swipeValue = Mathf.Sign(touch.position.x - startPos.x);
  80. if (swipeValue > 0)//right
  81. {
  82. //MoveRight ();
  83. //Swipe.text = "Right Swipe";
  84. }
  85. else if (swipeValue < 0)//left
  86. {
  87. //MoveLeft ();
  88. //Swipe.text = "Left Swipe";
  89. }
  90. }
  91. break;
  92. }
  93. }
  94. }
  95. function OnCollisionEnter2D(coll: Collision2D) {
  96. if(coll.gameObject.CompareTag("ground")){
  97. anim.SetFloat("hf",0.0);
  98. jumped=false;
  99. combo = 0;
  100. GUIcombo.text = "COMBO: " + combo;
  101. }
  102. if(coll.gameObject.CompareTag("enemy") && jumped==true){
  103. other.isdying=true;
  104. //Destroy(coll.gameObject);
  105. jumpup();
  106. jumped=true;
  107. combo += 1;
  108. GUIcombo.text = "COMBO: " + combo;
  109. }
  110. if(coll.gameObject.CompareTag("enemy") && jumped==false){
  111. lives -=1;
  112. GUIlives.text = "LIVES: " + lives;
  113. }
  114. }
  115. function slam(){
  116. Player.rigidbody2D.AddForce(new Vector2(0,-3000), ForceMode2D.Force);
  117. }
  118. function glide(){
  119. Player.rigidbody2D.AddForce(Vector2(0,600), ForceMode2D.Force);
  120. }
  121. function jumpup(){
  122. Player.transform.Translate(Vector3(Input.GetAxis("Vertical") * speed * Time.deltaTime, 0, 0));
  123. Player.rigidbody2D.velocity = Vector2(0,10);
  124. if(jumplevel2==true){
  125. Player.rigidbody2D.velocity = Vector2(0,13);
  126. }
  127. if(jumplevel3==true){
  128. Player.rigidbody2D.velocity = Vector2(0,16);
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement