Unity game development 2d- delivery driver

Hey I need some help. The problem which I am facing is when my car goes over customer or speedup the both sprites disappear and from hiearchy too however the package one works good. Please help

Hi @hamna_azhar,

Welcome to our community! :slight_smile:

Do the customer and speedup also disappear from the Hierarchy? If not, there might be a problem with the renderer. Set the z-position of the background game objects (street, etc.) to 10 in the Inspector.

Did this help you fix the problem?


See also:

They do disappear from hierarchy

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? Maybe the packages get destroyed because they collide with something?

For testing purposes, you could comment out all Destroy() methods in your code. Save your code and test your game again. If the game objects do not disappear anymore, try to figure out which Destroy() method destroys them.

Also check all your game objects to ensure that none of them has got the wrong script attached. For instance, a street game object is not supposed to have the car script attached to its Inspector.

1 Like

I have tried what you said. I don’t know where the problem is I have checked everything and have been using destroydelay but the results are same. If I exclude the destroy from my script nothing disappears but if I exclude it everything happens the same.

Fantastic. That’s important information because you figured out that the problem occurs only if Destroy gets called.

Check the customer and the speedup. Do they have the correct scripts/components attached to their respective Inspector?

If the player object destroys the game objects, check if there is an if-condition which prevents other game objects from being destroyed. If there is no if-statement, the player destroys “everything”.

How are you getting on with this problem, @hamna_azhar?

It is still the same. If I remove the destroy script all is good but if I don’t it does the same thing

Could you please share your relevant code as formatted text?


See also:

here it is and this script is only on my car which is supposed to do pick and drop stuff

Check the tags of your game objects. Maybe OnTriggerEnter2D destroys the other game objects because of the tags.

the tags are all the same like in the lecture video

Which messages get logged into your console when the game objects disappear from your Hierarchy?

Generally, game objects do not destroy themselves unless you load a new scene, which you don’t. There must be a reason why they get destroyed. If you call the Destroy method somewhere in your code, check the conditions. Then add Debug.Logs to your code to figure out if the conditions are evaluated to true even though you expected them to be evaluated to false.

Privacy & Terms