Advertisement
jezzye13

SpawnDestroyer

Jun 25th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Level11Jessey
  5. {
  6.     public class SpawnDestroyer : MonoBehaviour
  7.     {
  8.         [SerializeField] private IDamageableObject m_DamageblePart;
  9.  
  10.         private void Start()
  11.         {
  12.             if (m_DamageblePart != null)
  13.             {
  14.                 m_DamageblePart.DamageEvent += OnDamage;
  15.                 m_DamageblePart.DeathEvent += OnDeath;
  16.             }
  17.         }
  18.  
  19.         private void OnDestroy()
  20.         {
  21.             if (m_DamageblePart == null)
  22.                 return;
  23.  
  24.             m_DamageblePart.DamageEvent -= OnDamage;
  25.             m_DamageblePart.DeathEvent -= OnDeath;
  26.         }
  27.  
  28.         private void OnDamage(int removedHealth) { }
  29.  
  30.         private void OnDeath()
  31.         {
  32.             Destroy(gameObject);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement