I tried to make an if statement

i tried to add an if statement that took my stationary objects like houses and trees and rocks and only did the “oh no i hit something” debug log
and i typed it in

void OnCollisionEnter2d(Collision2d other)
{
if (other.tag == “StationaryObjects”)
Debug.Log “oh no a solid object”

and it didn’t work it said it couldn’t identify the tag or something anyway if i want to specify you hit this thing so my person yells “eek” but its multiple somethings how do i do that

Also follow up question why does the statement
hasPackage = false;
only need one equals but the statement
if (other.tag == “package” && !hasPackage)
has 2 equals how are they different and if you have already gone over this could you reference where you went over this thank you

What did it actually say?

It depends on what you’re trying to do.

For this line, you’re telling the program that you want the hasPackage variable to become false. In other words, you’re assigning false to hasPackage.

This one is checking to see if other.tag equals “package”.

You could do:
if (other.tag = “package” && !hasPackage)

But it will have very different outcome than the previous (double equals) version. It would assign “package” to other.tag (and seeing this assignment will be true in this instance) then it will check if hasPackage is false. If it is, it would run the next part of the program.

1 Like

THANk you that makes so much sense! As for my first question, It wound up being something that was addressed in the next lesson and I was confusing it by trying to tell it to trigger but it was a collider and visual studio was like, “NO?! what are you doing panicked computer noises” lol
Which is not as bad as when I completely started the class over because I kept spelling input as Imput and i thought i had utterly broken unity … sigh it was a sad day

Privacy & Terms