Pro_Unit

Weapon

May 10th, 2020
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. using System;
  2.  
  3. using UnityEngine;
  4.  
  5. public class Weapon : MonoBehaviour
  6. {
  7.     [SerializeField] private GameObject _buletPrefab;
  8.     [SerializeField] private Transform _launchPivot;
  9.     public event Action OnFire;
  10.  
  11.     public void Fire()
  12.     {
  13.         var lootAtLaunchPivotRotation = Quaternion.LookRotation(_launchPivot.forward);
  14.  
  15.         var bulletInstance = Instantiate(_buletPrefab, _launchPivot.position, lootAtLaunchPivotRotation);
  16.  
  17.         var bullet = bulletInstance.GetComponent<Bullet>();
  18.        
  19.         bullet.Thorw();
  20.  
  21.         OnFire?.Invoke();
  22.     }
  23. }
Add Comment
Please, Sign In to add comment