Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. if (gameIsPlaying == false) {
  2. return;
  3. }
  4.  
  5. if (isDead == true) {
  6. return;
  7. }
  8. if (isJumpingUp) {
  9. if (this.transform.position.x > JumpTargetLocation.x) {
  10. this.transform.position = new Vector3 (this.transform.position.x - (movingSpeed * Time.deltaTime), this.transform.position.y, this.transform.position.z);
  11. if (this.transform.position.x > midWayPointX) {
  12. this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y + jumpHeightIncrement * Time.deltaTime, this.transform.position.z);
  13.  
  14. } else {
  15. this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y - jumpHeightIncrement * Time.deltaTime, this.transform.position.z);
  16. }
  17.  
  18. } else {
  19. isJumpingUp = false;
  20. this.transform.position = new Vector3 (transform.position.x, initialPositionY, transform.position.z);
  21. }
  22.  
  23. } else if (isJumpingDown) {
  24. if (this.transform.position.x < JumpTargetLocation.x) {
  25. this.transform.position = new Vector3 (this.transform.position.x + (movingSpeed * Time.deltaTime), this.transform.position.y, this.transform.position.z);
  26. if (this.transform.position.x < midWayPointX) {
  27. this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y + jumpHeightIncrement * Time.deltaTime, this.transform.position.z);
  28.  
  29. } else {
  30. this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y - jumpHeightIncrement * Time.deltaTime, this.transform.position.z);
  31. }
  32.  
  33. } else {
  34. isJumpingDown = false;
  35. this.transform.position = new Vector3 (transform.position.x, initialPositionY, transform.position.z);
  36. }
  37.  
  38. } else if (isJumpingLeft) {
  39. if (this.transform.position.z > JumpTargetLocation.z) {
  40. this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y, this.transform.position.z - (movingSpeed * Time.deltaTime));
  41. if (this.transform.position.z > midWayPointX) {
  42. this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y + jumpHeightIncrement * Time.deltaTime, this.transform.position.z);
  43. } else {
  44. this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y - jumpHeightIncrement * Time.deltaTime, this.transform.position.z);
  45. }
  46.  
  47. } else {
  48. isJumpingLeft = false;
  49. this.transform.position = new Vector3 (transform.position.x, initialPositionY, transform.position.z);
  50. }
  51.  
  52. } else if (isJumpingRight) {
  53. if (this.transform.position.z < JumpTargetLocation.z) {
  54. this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y, this.transform.position.z + (movingSpeed * Time.deltaTime));
  55. if (this.transform.position.z < midWayPointX) {
  56. this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y + jumpHeightIncrement * Time.deltaTime, this.transform.position.z);
  57. } else {
  58. this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y - jumpHeightIncrement * Time.deltaTime, this.transform.position.z);
  59. }
  60.  
  61. } else {
  62. isJumpingRight = false;
  63. this.transform.position = new Vector3 (transform.position.x, initialPositionY, transform.position.z);
  64. }
  65. }
  66.  
  67. if (isPlayingDeathAnimation == true) {
  68. UpdateDeathAnimation();
  69. }
  70.  
  71.  
  72. }
  73.  
  74.  
  75. void SpawnNewStrip() {
  76.  
  77. int stripsPrefabCount = poolOfStripsPrefabs.Length;
  78. int randomNumber = Random.Range (0, stripsPrefabCount);
  79.  
  80. GameObject item = poolOfStripsPrefabs [randomNumber] as GameObject;
  81.  
  82. Transform itemChildTransform = item.transform.GetChild(0) as Transform;
  83. Transform itemChildOfChildTranform = itemChildTransform.GetChild (0) as Transform;
  84.  
  85. float itemWidth = itemChildOfChildTranform.gameObject.GetComponent<Renderer> ().bounds.size.x;
  86.  
  87. GameObject lastStrip = strips [strips.Count - 1] as GameObject;
  88.  
  89. GameObject newStrip = Instantiate (item, lastStrip.transform.position, lastStrip.transform.rotation) as GameObject;
  90. newStrip.transform.position = new Vector3 (newStrip.transform.position.x - itemWidth, newStrip.transform.position.y, newStrip.transform.position.z);
  91. strips.Add (newStrip);
  92. }
  93.  
  94. void OnTriggerEnter(Collider other){
  95.  
  96. if (other.gameObject.tag == "Mail") {
  97. Debug.Log ("player take Mail");
  98. Score += 25;
  99. scoreText.text = "score; " + Score.ToString ();
  100.  
  101. Destroy (other.gameObject);
  102.  
  103. this.GetComponent<AudioSource> ().PlayOneShot (mailClip);
  104. }
  105.  
  106. if (other.gameObject.tag == "Enemy") {
  107. Debug.Log ("player are dead");
  108. DeathAnimation();
  109. }
  110.  
  111. if (other.gameObject.tag == "obstacle") {
  112. Debug.Log ("player hit obstacle");
  113.  
  114.  
  115. float offsetUpDown = 0;
  116. float offsetLeftRight = 0;
  117.  
  118. if(isJumpingUp){
  119. offsetUpDown = 2.5f;
  120. }
  121.  
  122. else if(isJumpingDown){
  123. offsetUpDown = -2.5f;
  124. }
  125.  
  126. else if(isJumpingLeft){
  127. offsetLeftRight = 2.5f;
  128. }
  129.  
  130. else if(isJumpingRight){
  131. offsetLeftRight = -2.5f;
  132. }
  133.  
  134.  
  135. transform.position = new Vector3(transform.position.x + offsetUpDown, initialPositionY, transform.position.z + offsetLeftRight);
  136. isJumpingUp = isJumpingRight = isJumpingLeft = isJumpingDown = false;
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement