Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PowerUp : MonoBehaviour {
- public bool boosting = false;
- public GameObject effect;
- public AudioSource clip;
- private void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.CompareTag("Player"))
- {
- if (!boosting)
- {
- clip.Play();
- GameObject explosion=Instantiate(effect, transform.position, transform.rotation);
- Destroy(explosion, 2);
- GetComponent<MeshRenderer>().enabled = false;
- GetComponent<Collider>().enabled = false;
- TankMovement.m_Speed = 20f;
- boosting = true;
- Debug.Log(boosting);
- StartCoroutine(coolDown());
- }
- }
- else if(other.gameObject.CompareTag("Player1"))
- {
- if(!boosting)
- {
- clip.Play();
- GameObject explosion=Instantiate(effect, transform.position, transform.rotation);
- Destroy(explosion, 2);
- GetComponent<MeshRenderer>().enabled = false;
- GetComponent<Collider>().enabled = false;
- TankMovement1.m_Speed1 = 20f;
- boosting = true;
- Debug.Log(boosting);
- StartCoroutine(coolDown());
- }
- }
- }
- private IEnumerator coolDown()
- {
- if (boosting == true)
- {
- yield return new WaitForSeconds(5);
- {
- boosting = false;
- GetComponent<MeshRenderer>().enabled = true;
- GetComponent<Collider>().enabled = true;
- Debug.Log(boosting);
- // Destroy(gameObject);
- }
- }
- }
- private void Update()
- {
- if (boosting == false)
- {
- TankMovement.m_Speed = 12f;
- TankMovement1.m_Speed1 = 12f;
- }
- }
- }
Add Comment
Please, Sign In to add comment