- Home /
Problem with multiplayer unity.
I want to make simple fps multiplayer game but I have a small problem. When I attack another player I want to to subtract 10 point from his hp. Multiplayer was made with Photon Engine so every players are the same prefab. Sorry for my bad english, I hope you understand my problem.
if (Input.GetMouseButtonDown(0) && Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, attackDistance)) //attack distance = 2.5f, hit = raycast hit
{
if (hit.transform.CompareTag("Player")) //hit a another player who is connected to the server
{
//hitted player hp -= 10
}
}
Answer by GetLitGames · Mar 20 at 10:19 AM
You want to move the input code into a component that you remove from non-local copies of the players because otherwise your code runs 3 times (if there were 3 player bodies in the scene). You could also just surround it in an IF statement rather than creating some code that removes the component from non-local player bodies but you should get used to thinking about better design too. I know you are excited about making a multiplayer game but your is very basic and shows that you need to do some tutorials both with Unity and Photon because you will have a very hard time developing a multiplayer game without even knowing Unity very well. You can use your own project as a tutorial but you should still watch and follow some tutorials because you will see other people who are more experienced and learn some good Unity habits and understanding outside of just the topic they discuss.