- Home /
Question by
NFMynster · Aug 30, 2016 at 12:29 AM ·
networkingmultiplayeroncollisionenterserverside
UNET OnCollisionEnter issues
Hello again!
I'm having some issues with OnCollisionEnter as my code only works on the remote clients once in a while, and I really don't know why.
void OnCollisionEnter(Collision col)
{
CheckHit(col.gameObject);
}
[Client]
void CheckHit(GameObject col)
{
if (col.GetComponent<Collider>().CompareTag("Ball"))
{
if (col.gameObject.GetComponent<BallOwner>().lastTouchedBy == TeamSetup.Team.Unassigned)
{
return;
}
//If the ball is has been touched by another team than ourselves, then we are hit
if (col.gameObject.GetComponent<BallOwner>().lastTouchedBy != gameObject.GetComponent<TeamSetup>().currentTeam)
{
OnHit();
CmddebugMessage("On hit is called");
//Reset the ball again, so that we don't get hit by a dead ball
RpcResetBall(col.gameObject);
}
}
}
Note the code always works when called from the server, as being the server throws the ball at a remote client.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612091824im_/https://answers.unity.com/themes/thub/images/avi.jpg)