The Package dont print me "package pick up"

when i write:

if (other.tag == “Package”)

    {

      Debug.Log("Package picked up");  

    }

it doesn’t work and print nothing


but when write:

if (other.tag != “Package”)

    {

      Debug.Log("Package picked up");  

    }

its working perfect…



Screenshot 2024-05-27 214051

(the code in the first picture doesn’t work, the code in the last picture is working)

Hi NiceXD,

Welcome to our community! :slight_smile:

Thanks for sharing screenshots of what you did and have in the Unity Editor. That’s helpful.

Please take a look at this:
image

In the Inspector, we can see the ‘package’ game object. This game object has got the ‘Package’ tag assigned. (Notice the word ‘this’ in this sentence because it is important. ;))

We can also see the Delivery component in the Inspector. If you log tag into your console, you’ll see ‘package’ in yoru console. tag is short for this.tag. (That’s why I emphasised ‘this’.)

Does that make sense so far?

Since ‘this’ is the package, the other game object is very likely not a package because, otherwise, packages would collide with packages. If the other game object is the Player, other.tag == 'Package' would be true only if the Player has got the ‘Package’ tag assigned.

Question: Does it make sense to assign the ‘Package’ tag to the Player?
Answer: No, it doesn’t. The Player is a car, so the ‘Player’ or ‘Car’ tag makes more sense.

You solved the problem by checking if the other game object does not have the ‘Package’ tag assigned. If the player is the only moving collider, the solution is fine.

However, what happens if there are other moving colliders which might collide with the package?


As you probably noticed, I avoided to tell you the problem and solution directly. The reason for that is: There are often multiple ways to make things work. If you apply simple logic, you can modify the code to solve problems your way. That’s fine. If you want to follow Rick’s logic, you probably spotted the actual problem after reading my hints. If not, please let me know. :slight_smile:

Here is another hint if you need one:

Is your package able to drive? If not, what’s the purpose of line 9 in the Delivery class?


See also:

I was just going to tell you what is wrong. @Nina’s got you covered.


i change in line 13 the “other” to “this” and its worked. thank you!
but i still don’t understand why in the video (of the course) the “other” in line 13 worked for him, and for me it didn’t work.

Uhm, this is not what @Nina was pointing you at.

This script is attached to a package, so the tag will always be “Package”. Perhaps this should be attached to something that is not the package and that could possibly touch the package…

sorry that it hard for me to understand it. but i don’t get it… the script on the car. and not on the package, so i don’t understand why its not working.


Screenshot 2024-05-28 110442

The script should be on the car, not on the package. It was on the package, but it’s not on the car or the package, now

but the script on the car…Or it’s not how you put a script on the car. But you can see in the picture that it is on the car (I dragged the script) on the car as it was said in the video to do.

No, it’s not on the car. This screenshot does not show the script at all. You are confusing Driver with Delivery. There is no Delivery script on this car

Oh sorry, I got the names mixed up, I was sure it was on him all this time… sorry…
thank you.

No need to apologise. It’s my pleasure. Enjoy

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms