- Home /
Question by
$$anonymous$$ · Sep 15, 2019 at 07:44 AM ·
networkingnetworkracingracing gamefinish
in a multiplayer racing game how would you determine which car crossed the finish line first?
how would you approach this problem ?
Im thinking something like putting an empty gameobject called 1st in the scene
when any car crosses finish line it finds 1st gameobject in the scene and destroys it over network, and is declared a winner. when second car crosses finish line it cant find 1st gameobject because it is already destroyed so player is declared loser.
I want to know if there are more clever approach to this problem.
Comment
Answer by alireza97 · Sep 15, 2019 at 11:00 AM
you can easily put an empty collider and check is Trigger in the end line and add this simple code on it.
GameObject Winner = null;
void OnTriggerEnter(Collider other)
{
if (!Winner)
{
Winner = other.gameObject;
//First one cross the line
}
else
{
//Second one cross the line
}
}