| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PowerDrop : MonoBehaviour
- {
- public float powerAmount = -100.0f;
- private float timeTillSelfPop;
- [SerializeField]
- private UnityEngine.UI.Text textField;
- private bool popped = false;
- void OnTriggerEnter(Collider other)
- {
- if (!popped)
- {
- if (other.tag == "Player")
- {
- other.GetComponent<Player>().PowerLevel += powerAmount;
- popped = true;
- Pop();
- }
- }
- }
- // Use this for initialization
- void Start ()
- {
- textField.text = "+" +powerAmount.ToString();
- timeTillSelfPop = 5.2f;
- }
-
- // Update is called once per frame
- void Update ()
- {
- timeTillSelfPop -= Time.deltaTime;
- if (timeTillSelfPop < 0)
- {
- Pop();
- }
- }
- private void Pop()
- {
- GameObject.Destroy(gameObject);
- }
- }
|