Destroying prefabs breaking scripting for other prefabs
Hello,
I have about 5 pertinent scripts in this games current bug. I would be very grateful for some help. I've read it has to do with how you destroy objects Vs prefabs. But I've tried several different things and can't get it quite right.
Scripts attached to my boat:
Boatspawn == creates a boat
BoatMove == moves a boat towards the shore. Once it reaches the destination, it loops through a couple Do - While loops and calls a function in a script (Soldier_Spawner) to spawn prefabs of a soldier -- calling and generating 15 soldiers.
Soldier_Spawner == script that instantiates the soldier prefabs called by BoatMove.
Scripts attached to my turret:
Turret_Controls == has joysticks to control the turret and a button to shoot a raycast. When the raycast returns a hit marker for hitting a soldier, it calls a function in a script(DestroySoldier) that destroys the soldier object and instantiates a bloody mess where the soldier used to be.
Scripts attached to my Soldiers:
Wander == Sets a random waypoint up to 10 units away and makes the soldier walk towards it. When the soldier is facing a specific direction (towards a turret) the soldiers gun shoots.
DestroySoldier == destroys the soldier object and instantiates a bloody mess where the soldier used to be.
The issue is that if DestroySoldier gets called on one prefab soldier, the game throws errors saying it can't find a gameobject while trying to run the wander script. Then all the still alive prefab soldiers walk straight in their current direction forever. If I don't destroy any prefabs, they continue to loop through the scripts without a problem. So I can't successfully kill 1 without messing up the others. Like they are all still connected somehow. I can post scripts if it will help, or invite people to my collaboration if it would help. I'm really struggling here.
Your answer
Follow this Question
Related Questions
Instantiated bullet wont destroy 1 Answer
Destroy prefabs after they have been instantiated (C#) 1 Answer
How to add Components to some individuals parts of a prefab 1 Answer
How do I destroy a Instantiated UI Image that is a prefab but is pused on the Canvas? 0 Answers
Why wont the target be destroyed? 0 Answers