PowerDrop.cs 812 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. [SerializeField]
  8. private UnityEngine.UI.Text textField;
  9. private bool popped = false;
  10. void OnTriggerEnter(Collider other)
  11. {
  12. if (!popped)
  13. {
  14. if (other.tag == "Player")
  15. {
  16. other.GetComponent<Player>().PowerLevel += powerAmount;
  17. popped = true;
  18. Pop();
  19. }
  20. }
  21. }
  22. // Use this for initialization
  23. void Start()
  24. {
  25. textField.text = powerAmount.ToString();
  26. }
  27. // Update is called once per frame
  28. void Update()
  29. {
  30. }
  31. private void Pop()
  32. {
  33. GameObject.Destroy(gameObject);
  34. }
  35. }