Finish SFX plays twice

OnTriggerEnter2D is being called twice, once with the head circle collider and once with the snowboard capsule collider, this makes it so the finishing sfx is being played twice. How do i stop this? In case i somehow missed something here is my code:


The reason im using PlayOneShot for this is because i was trying different things but it doesn’t seem to make a difference

1 Like

Oh, I misunderstood, I would say only make it so that only the circle collider processes crash, not the snowboarder board

1 Like

I do not know how to do this, how do i stop the finish line trigger from being called by the non trigger snowboard collider. I dont understand how in the video the same thing doesnt happen seeing as i seem to have the same setup as the course

1 Like

Oh man, I completely misunderstood your question, I have this game on my computer so let me check what I have for an easy fix, sorry.

Edit: I’m junt going to go on my computer and see what’s up with my snowboarder so I can easily tell what Rick does for the triggers

1 Like

Ok I think I know what it is, you should only have trigger enabled on your circle collider not your capsule collider, if you want me to explain why let me know I’m just getting this quick answer out.

Hope this helps!

1 Like

The thing is, i dont have trigger enabled on the capsule collider

1 Like

Then I’d double check your not checking for collision, because you shouldn’t have trigger playing twice, because its only attached to a trigger, make sure your not checking for collision or trigger on any of your scripts.

Also make sure you don’t have multiple things that are tagged as “player” or else it will play twice.

1 Like

Im sure im only checking for ontrigger not oncollision as you can see in my screenshot, the only other ontrigger i have is in my crashing script but thats also the same as in the course and only the player is tagged as player.
here are the screenshots i have of the components of both the finish line and the player, maybe this will help.


1 Like

Interesting, you have a problem that should be easy but I just don’t see what it is…

1 Like

I would double check just to see that you don’t have anything else with the tag player, because your script is checking for a tag named player,.

1 Like

Also if you click on the message on the console it should tell you where it comes from, that could be just to check if you don’t have another place where trigger is being called. Also make sure you didn’t attach a script in a place where you don’t want it

1 Like

I have a debug.log that shows up twice in the console with both the exact same text, its how i know that the script is being called twice by both the circle collider and capsule collider, i’ve checked like 5 times to see if scripts have been applied twice somewhere but that is also not the case. and the player tag is also only on the player parent gameobject.

1 Like

Interesting, I wonder if because there is the upper body and the lower body of the snowboarder, and there’s player tags on that, if there is a player tag on both of those, try only having the tag on the parent game object.

The drop-down of the player game object there is the lower body and upper body, if both have a player tag that could be why

1 Like

Neither have the player tag, the player tag is only on the parent player gameobject

1 Like

Ok so I think the best option would to be having a bool that checks to see if trigger has passed

using UnityEngine;

public class PlayOnceTrigger : MonoBehaviour
{
    public AudioClip audioClip;
    private bool hasPlayed = false;

    private void OnTriggerEnter(Collider other)
    {
        if (!hasPlayed && audioClip != null)
        {
            AudioSource.PlayClipAtPoint(audioClip, transform.position);
            hasPlayed = true;
        }
    }
}

Something like this(obviously it’s not the same, but you see the point of the script) so that trigger can only play once, hopefully this can get us in the right direction.

This way we have bools that can see if something happened, I have two bool examples in the if statement

1 Like

Alright I will try this and just move on instead of trying to find the issue, thanks for the help and happy birthday!

1 Like

Thanks for the birthday wishes, hopefully the issue gets solved!

1 Like

I tried it and it works! so thanks again.

1 Like

Glad I could help!

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

Privacy & Terms