I created a script for shooting in unity. In a basic sense I made it to where I can set a specific number of bullets that can be shot ,how long they last, and when to destroy them. I also added in for the bullets to return back into the hierarchy after being used. I receive an error message
“The object of type ‘GameObject’ " has been destroyed but you are still trying to access it. Script should either check if null or you shouldn’t destroy the object.” even though I told it to return after it had been destroyed.
Here is the section of the script that is said “incorrect.”
public GameObject GetBullet() {
foreach (GameObject bullet in bullets) {
if (!bullet.activeInHierarchy) {
bullet.SetActive (true);
return bullet;
}
}