Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class ball : MonoBehaviour
  7. {
  8.  
  9. Rigidbody rb;
  10. public bool jump, bjump, ss;
  11. float z, startTouch, x;
  12. public GameObject next;
  13.  
  14. // Use this for initialization
  15. void Start()
  16. {
  17. Application.targetFrameRate = 60;
  18. rb = GetComponent<Rigidbody>();
  19. jump = false;
  20. ss = true;
  21. bjump = false;
  22. rb.velocity = new Vector3(0, -4f, 0);
  23. }
  24.  
  25. public void Update()
  26. {
  27. if (transform.position.y <= -.75f)
  28. {
  29. ss = false;
  30. }
  31.  
  32. Touch();
  33.  
  34. if (z + 4.5f <= transform.position.z)
  35. {
  36. if (bjump == true)
  37. {
  38. if (z + 19.5f <= transform.position.z)
  39. {
  40. transform.position = new Vector3(transform.position.x, transform.position.y, z + 20f);
  41. rb.velocity = new Vector3(0, -4f, 0);
  42. bjump = false;
  43. }
  44. }
  45.  
  46. if (jump == true)
  47. {
  48. transform.position = new Vector3(transform.position.x, transform.position.y, z + 5f);
  49. rb.velocity = new Vector3(0, -4f, 0);
  50. jump = false;
  51. }
  52. }
  53. Vector3 tmpPos = transform.position;
  54. tmpPos.x = Mathf.Clamp(tmpPos.x, -2.25f, 2.25f);
  55. transform.position = tmpPos;
  56. }
  57.  
  58. public void OnCollisionEnter(Collision collisionInfo)
  59. {
  60. if (collisionInfo.collider.tag == "Untagged")
  61. {
  62. transform.position = new Vector3(transform.position.x, transform.position.y, next.transform.position.z);
  63. next.transform.position = new Vector3 (0, -1.4f, next.transform.position.z + 5f);
  64. rb.velocity = new Vector3(0, 10f, 9.5f);
  65. z = transform.position.z;
  66. jump = true;
  67. bjump = false;
  68. }
  69.  
  70. if (collisionInfo.collider.tag == "BigJump")
  71. {
  72. transform.position = new Vector3(transform.position.x, transform.position.y, next.transform.position.z);
  73. next.transform.position = new Vector3(0, -1.4f, next.transform.position.z + 20f);
  74. rb.velocity = new Vector3(0, 15f, 25.5f);
  75. z = transform.position.z;
  76. bjump = true;
  77. jump = false;
  78. }
  79.  
  80. if (collisionInfo.collider.tag == "Finish")
  81. {
  82. ss = false;
  83. Invoke("reset" , 1f);
  84. }
  85.  
  86. if (collisionInfo.collider.tag == "Respawn")
  87. {
  88. //death
  89. Invoke("reset", 1f);
  90. }
  91. }
  92.  
  93. public void reset()
  94. {
  95. SceneManager.LoadScene(0);
  96. }
  97.  
  98. public void Touch()
  99. {
  100. if (ss == true)
  101. {
  102. if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
  103. {
  104. int num = Input.GetTouch(0).fingerId;
  105. startTouch = Input.GetTouch(0).position.x;
  106. }
  107.  
  108. if (Input.touchCount > 0 && Input.GetTouch(0).fingerId == 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
  109. {
  110. x = Input.GetTouch(0).position.x - startTouch;
  111. if (x > 0)
  112. {
  113. float w = Screen.width;
  114. float a = x / w * (400);
  115. rb.MovePosition(transform.position + transform.right * Time.deltaTime * a);
  116. }
  117. else if (x < 0)
  118. {
  119. float w = Screen.width;
  120. float a = x / w * (400);
  121. rb.MovePosition(transform.position + transform.right * Time.deltaTime * a);
  122. }
  123. }
  124.  
  125. if (Input.touchCount > 0)
  126. {
  127. startTouch = Input.GetTouch(0).position.x;
  128. }
  129. }
  130. }
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement