This question was
closed Jun 05, 2018 at 10:52 AM by
sandeepraj.
Question by
sandeepraj · May 28, 2017 at 07:28 AM ·
unity 5playercollisionsunity multiplayer
I need help in kill a player with low hp on collision with other player in multiplayer
I am working on a multiplayer game for the first time in unity, and I need help detecting collision between player to player(different mesh but use same scripts) and kill the player with low health over network. my game has only players.
Can someone help me how would I do it.
Comment
Best Answer
Answer by PlexusDuMenton · May 28, 2017 at 08:02 AM
well , there is many way to make it you could use Physics.OverlapSphere
void Update()
{
Collider[] hitColliders = Physics.OverlapSphere(transform.Position, radius);
for (int i = 0, i < hitColliders.Length; i++)
{
if (hitColliders[i].GetComponent<PlayerScript>() != null)
{
hitColliders[i].GetComponent<PlayerScript>().YOURFUNCTIONWHENITCOLISEWITHANOTHERPLAYER();
}
}
}
adittionaly you can use layer system to reduce the collider
or you could even make a static script that handle all of your player's gameobject and their position and each frame check if distance is low enought (that may be easier for the computer to calcultate ^^)