How do I create a FPS health system such that the damage are calculated globally?


I currently got a multiplayer fps set up (w/o photon or other add-ons). When i start the game, the player both spawns and controls a prefab soldier.

So for my player health script:

#pragma strict

var health: int=100;

function OnGUI() {

function TakeDamage(Damage:int){

and on the bullet’s script:

function OnTriggerEnter(FPS:Collider){

When I(server side) fire and the bullet collides with the client’s capsule collider, health -1 on server’s side! Points are also deducted from client’s health. After multiple shots fired, the HP doesn’t even tally between the 2 sides. What is it that I’m doing wrong?

I suspect that the way i declared health makes it a shared variable between all players. (Is it?)

Also, when the health reduces to 0, I’ve tried to include Destroy(gameObject). On server side, the player’s prefab gets destroyed, but on client’s side, the health isnt even 0 yet (and it doesnt get destroyed).

Help please!!

Now i do belive this is Java or something and i do C# but i can help a tiny bit hopefully, you can change the trigger void On TriggerEnter(Collider coll) {
//this is for c# but try and make this go into Java or JavaScript
change that to collision
void OnCollisionEnter(Collision Coll)
//Damage code

and go to whatever you put this script on, go to the collider in it and make sure than is trigger is false
if that does not work check if is trigger is set to true otherwise if you have a script saying Trigger and the collider is not a trigger it will cause some problems :slight_smile: If you are confused on how to add this into Java (Or JavaScript) Than they are soo many tutorials on JS or Java with unity that pro cover this :))