Points.cs 731 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class Points : MonoBehaviour
  6. {
  7. [HideInInspector] public Counter counter;
  8. [Header("Число очков")]
  9. [SerializeField] private int points=0;
  10. [Header("Число здоровья (от 0 до 100)")]
  11. [SerializeField] private int health=0;
  12. [HideInInspector]
  13. public hp HP;
  14. private void Start()
  15. {
  16. counter = FindObjectOfType<Counter>();
  17. HP = GameObject.FindGameObjectWithTag("Player").GetComponent<hp>();
  18. }
  19. private void OnTriggerStay2D(Collider2D other)
  20. {
  21. HP.SetHealth(health);
  22. counter.total += points;
  23. Destroy(this.gameObject);
  24. }
  25. }