Help please

I have a problem where every trigger acts as a boost, this is after a wipe because of a syntax error. I tagged all things accordingly. Please help

Hi Rens,

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

And what does ‘every trigger’ mean in your case? What did you expect to happen? What happened instead?

Bear in mind that Unity is not intelligent, and it cannot read out minds. If we define in our code that the car is supposed to get a boost when touching a trigger collider, it will get a boost. If we don’t want it to get a boost in certain cases, we have to define those cases in our code, for example, with if-statements.

this is the piece of code:
void OnTriggerEnter2D(Collider2D other)

 {

    if (other.tag == "boost");

    {

        Debug.Log("boosted");

    }

 }

and with all tagged I mean that I tagged a customer a package and a boost.
code for those here:
void OnTriggerEnter2D(Collider2D other)

{

   if (other.tag == "Package" && !HasPackage)

 {

   Debug.Log("Package picked up");

   HasPackage = true;

   spriteRenderer.color = hasPackageColor;

   Destroy(other.gameObject, destroyDelay);

 }

  if (other.tag == "Customer" && HasPackage)

 {

    Debug.Log("Package Delivered");

    HasPackage = false;

    spriteRenderer.color = noPackageColour;

 }

Which of the Debug.Log messages appeared in your console? Is a message that you expected to appear missing?

Make sure there are no semicolons behind the parentheses of an if-condition. Remember you can also look at the lecture code changes via the link in the Resources of each lecture.

1 Like

This is the problem

1 Like

Sorry I’m not a native English speaker so I don’t know what you mean with semicolon

oh never mind I fixed it! Thank you so much for the help!

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

Privacy & Terms