Hello! I just recently picked up Unity (as in 3 days ago) and I’ve made decent progress on my game, but I’m at a loss now. Figure I’d try my luck at a forum post before I go to bed.
I’m making a hockey game. Currently what happens, is that when the Puck crosses a goal line, it updates both home and away scores. I can’t find a way to select a specific trigger collider. On Trigger Enter seems to be my only option, and just makes the puck react to ANY trigger. What am I missing here? Also, feel free to suggest any trimming on this if you notice something that can be done better.
OnTriggerEnter has a Collider parameter (it’s right there in your screenshot). This tells you which collider you collided with. You need to inspect that collider and do some kind of check against it. Perhaps check if it is equal to one goal collider or another. or maybe attach another component to the goals, and go from that collider to that component (using GetComponent) and read which goal it is from there.
Thanks for the advice, I couldn’t figure out how to make GetComponent work for me, but I figured another way. I made a scene variable for each net, which let me target the Box Collider Trigger itself. Then I used Get Scene Variable, and ran it and the collider parameter from the On Trigger Event to an Equal check. The On Trigger Event automatically grabs the trigger collider of the net it’s attached to. So when compared, it’s the same as the variable I made. Then it simply goes through a True/False. Currently I have two versions of this “script”. One for each net. But I could probably shorten it by having True score for home, and False score for away.
Thanks peeps! I’ll post this kind of question in scripting next time. I didn’t see the VISUAL scripting forum for some reason, just regular scripting and I wasn’t sure if this counted. My bad.
Glad you got it working. You should definitely be able to get this to work with a single script for both goals somehow (a per-instance variable of some kind?). I don’t know much about visual scripting though. In a normal Unity MonoBehaviour script I would just have a property on the script called “OwnedByTeam” which designates which team the goal belongs to. Then you can set the value in the inspector for that script. Should be able to do something similar in Visual Scripting but i’m not sure how.