Guest User

Untitled

a guest
Dec 12th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PowerUp : MonoBehaviour {
  5.  
  6. public bool boosting = false;
  7. public GameObject effect;
  8. public AudioSource clip;
  9.  
  10.  
  11. private void OnTriggerEnter(Collider other)
  12. {
  13. if (other.gameObject.CompareTag("Player"))
  14. {
  15. if (!boosting)
  16. {
  17. clip.Play();
  18. GameObject explosion=Instantiate(effect, transform.position, transform.rotation);
  19. Destroy(explosion, 2);
  20. GetComponent<MeshRenderer>().enabled = false;
  21. GetComponent<Collider>().enabled = false;
  22.  
  23. TankMovement.m_Speed = 20f;
  24. boosting = true;
  25. Debug.Log(boosting);
  26. StartCoroutine(coolDown());
  27. }
  28.  
  29.  
  30. }
  31. else if(other.gameObject.CompareTag("Player1"))
  32. {
  33. if(!boosting)
  34. {
  35. clip.Play();
  36. GameObject explosion=Instantiate(effect, transform.position, transform.rotation);
  37. Destroy(explosion, 2);
  38. GetComponent<MeshRenderer>().enabled = false;
  39. GetComponent<Collider>().enabled = false;
  40.  
  41. TankMovement1.m_Speed1 = 20f;
  42. boosting = true;
  43. Debug.Log(boosting);
  44. StartCoroutine(coolDown());
  45. }
  46.  
  47. }
  48. }
  49.  
  50. private IEnumerator coolDown()
  51. {
  52. if (boosting == true)
  53. {
  54. yield return new WaitForSeconds(5);
  55. {
  56. boosting = false;
  57. GetComponent<MeshRenderer>().enabled = true;
  58. GetComponent<Collider>().enabled = true;
  59. Debug.Log(boosting);
  60. // Destroy(gameObject);
  61.  
  62. }
  63. }
  64. }
  65.  
  66.  
  67.  
  68. private void Update()
  69. {
  70. if (boosting == false)
  71. {
  72. TankMovement.m_Speed = 12f;
  73. TankMovement1.m_Speed1 = 12f;
  74. }
  75.  
  76. }
  77.  
  78. }
Add Comment
Please, Sign In to add comment