Pro_Unit

WeaponParticleEffects

May 10th, 2020
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using System;
  2.  
  3. using UnityEngine;
  4.  
  5. [RequireComponent(typeof(Weapon))]
  6. public class WeaponParticleEffects : MonoBehaviour
  7. {
  8.  
  9.     [SerializeField] private float _lifeTime = 3f;
  10.     [SerializeField] private GameObject _effectPrefab;
  11.     private Weapon _weapon;
  12.     private void Awake()
  13.     {
  14.         _weapon.OnFire += OnWeaponFire;
  15.     }
  16.     private void OnDestroy()
  17.     {
  18.         _weapon.OnFire -= OnWeaponFire;
  19.     }
  20.     private void OnWeaponFire()
  21.     {
  22.         var effect = Instantiate(_effectPrefab, _weapon.transform.position, Quaternion.identity, _weapon.transform);
  23.         Destroy(effect, _lifeTime);
  24.     }
  25. }
Add Comment
Please, Sign In to add comment