using System.Collections; using System.Collections.Generic; using UnityEngine; public class GunActiveSample : MonoBehaviour { public GameObject Bullet; [SerializeField] private Transform barrelLocation; [SerializeField] private float destroyTimer = 2f; [SerializeField] private float shotPower = 500f; void Start() { if (barrelLocation == null) { barrelLocation = transform; } } public void FireGun() { GameObject BulletHead; // Create a bullet and add force on it in direction of the barrel BulletHead = Instantiate(Bullet, barrelLocation.position, barrelLocation.rotation); BulletHead.GetComponent().AddForce(barrelLocation.forward * shotPower); Destroy(BulletHead, 3); } }