Can anyone explain why/how the “on trigger enter 2D” and “Sprite Renderer set colour” set up targets the Germ 2 sprite? I don’t understand where the link is here between them and why one’s colour is affected but not the other, i.e., the germ sprite is not even mentioned here.
OnTriggerEnter2D
gives you the object that the object with the script graph (the player) collided with (germ 2). Germ 2 has a sprite renderer, so we get that sprite renderer from the collider (internally it will be using code that matches collider.GetComponent<SpriteRenderer>()
) and then sets the color on that sprite renderer. It doesn’t need to know what entered the trigger. It only needs to know that it was an object with a sprite renderer. It could be any object.
Hope this answers your question
Bixarrio has it right, well done!
Thank you, this is fantastic. Do we only get sprite renderer from germ 2 or could we access any of it’s information if we wish when using OnTriggerEnter2D?
Yes, you can get any of the components on it.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.