Hello there,
when I try to use OnCollisionEnter2D without tags, it works:
void OnCollisionEnter2D(Collision2D other)
{
moveSpeed = slowSpeed;
Debug.Log("You damaged your car!");
}
but when trying to use it with tags (as I want the car to slow down only when colliding with houses which are tagged House but to not slow down otherwise):
void OnCollisionEnter2D(Collision2D other)
{
if (other.tag == "House")
{
moveSpeed = slowSpeed;
Debug.Log("You damaged your car!");
}
}
I will get an error message:
Compiler Error CS1061
āCollision2Dā does not contain a definition for ātagā and no accessible extension method ātagā accepting a first argument of type āCollision2Dā could be found (are you missing a using directive or an assembly reference?).
This error occurs when you try to call a method or access a class member that does not exist.
How can I set up different behaviour when colliding with objects with different tags?
Btw. great course, I changed the behaviour a little so that you will cannot run over the customer as he has a rigid body but he has another collider around him so you just need to get close to him and also customer will point out that you do not have a package when you have none and also the game will be declared a victory when you deliver 3 packages.
Thanks
Laco