I'm following a code monkey tutoreal on making a third person game. I tried to copy his code but when he deletes the bullet on impact he can shoot again but when I do it, it does not work.
Bullet code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletProjectile : MonoBehaviour
{
private Rigidbody bulletRigidbody;
[SerializeField] private GameObject playerArmature;
[SerializeField] private Transform vfxHitEnemy;
[SerializeField] private Transform vfxMissEnemy;
private void Awake()
{
bulletRigidbody = GetComponent<Rigidbody>();
}
private void Start()
{
float speed = 20f;
bulletRigidbody.velocity = transform.forward * speed;
}
public void OnTriggerEnter(Collider other)
{
if (other.GetComponent<targetScript>() != null)
{
//hit target
Instantiate(vfxHitEnemy, transform.position, Quaternion.identity);
}
else
{
Instantiate(vfxMissEnemy, transform.position, Quaternion.identity);
}
Destroy(gameObject);
}
}
shooting code:
if (starterAssetsInputs.shoot)
{
Vector3 aimDir = (mouseWorldPosition - bulletSpawn.position).normalized;
Instantiate(pfBullletProjectile, bulletSpawn.position, Quaternion.LookRotation(aimDir, Vector3.up));
starterAssetsInputs.shoot = false;
}