PowerDrop.cs 991 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PowerDrop : MonoBehaviour
  5. {
  6. public float powerAmount = -100.0f;
  7. private float timeTillSelfPop;
  8. [SerializeField]
  9. private UnityEngine.UI.Text textField;
  10. private bool popped = false;
  11. void OnTriggerEnter(Collider other)
  12. {
  13. if (!popped)
  14. {
  15. if (other.tag == "Player")
  16. {
  17. other.GetComponent<Player>().PowerLevel += powerAmount;
  18. popped = true;
  19. Pop();
  20. }
  21. }
  22. }
  23. // Use this for initialization
  24. void Start ()
  25. {
  26. textField.text = "+" +powerAmount.ToString();
  27. timeTillSelfPop = 10.4f;
  28. }
  29. // Update is called once per frame
  30. void Update ()
  31. {
  32. timeTillSelfPop -= Time.deltaTime;
  33. if (timeTillSelfPop < 0)
  34. {
  35. Pop();
  36. }
  37. }
  38. private void Pop()
  39. {
  40. GameObject.Destroy(gameObject);
  41. }
  42. }