- Home /
 
Network Shoot/health script
Ok I am Making a network fps in unity and i am having some problems I made a health script and a shoot script so basically when the player shoots the other player the player hit loses health but the problem is they dont lose any health.
shoot script:
     var damage : int = 50;
     var meleeaim : Transform;
     var ammo = 15;
     var clips = 10;
     
     function Update() {
     if (Input.GetButtonDown("Fire1")) {
     attackdamage();
     //    animation.Play("shoot");
      }
      if (ammo <= 0 && clips >= 1) {
          reload();
      }    
     //if (animation.isPlaying == false) {
     //  animation.CrossFade("gunidel");
     //  }
     //  if (Input.GetKey(KeyCode.LeftShift)) {
     //      animation.CrossFade("swordrun");
     //  }
     // if (Input.GetKeyUp(KeyCode.LeftShift)) {
     //     animation.CrossFade("gunidel");
     // }
     }
     function attackdamage() {
             var hit : RaycastHit;
         if (Physics.Raycast(meleeaim.transform.position, meleeaim.transform.TransformDirection(Vector3.forward), hit)) {
         hit.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
         }
     }
     
     function shoot() {
         ammo -= 1;
     }    
     
     function reload() {
              clips -= 1;
              ammo = 10;
     }
 
 
               Health Script:
 var Health = 100;
 
 function ApplyDammage (damage : int)
 {
     Health -= damage;
     
     if(Health <= 0)
     {
         Dead();
     }
 }
 
 function Dead()
 {
     RespawnMenu.playerIsDead = true; 
     Debug.Log("Player Died");
 }
 
               network script:
 var gameName : String = "fragnass_game_make_original";
 var player : Transform;
 var spawnobject : Transform;
 private var refreshing : boolean;
 private var hostData : HostData[];
 private var poswidth : float;
 private var posheight : float;
 private var width : float;
 private var height : float;
 function Start() {
     poswidth = Screen.width * 0.05;
     posheight = Screen.width * 0.05;
     width = Screen.width * 0.1;
     height = Screen.width * 0.1;
 }
 
 function startServer() {
      Network.InitializeServer(18, 25001, !Network.HavePublicAddress);
      MasterServer.RegisterHost(gameName, "FPS Shooter Game", "This Is A FPS" );
 }
 
 function spawnplayer() {
     Network.Instantiate(player, spawnobject.position, Quaternion.identity, 0);
 }
 
 function OnServerInitialized() {
 Debug.Log("Server is initalized");
 spawnplayer();
 }
 
 function OnConnectedToServer() {
     spawnplayer();
 }
 
 function OnMasterServerEvent(mse : MasterServerEvent) {
     if (mse == MasterServerEvent.RegistrationSucceeded)
     Debug.Log("Server Registrated");
 }
 
 function refreshhostlist() {
     MasterServer.RequestHostList(gameName);
     refreshing = true;
     
 }
 
 function Update() {
     if (refreshing) {
         if (MasterServer.PollHostList().Length > 0) {
         refreshing = false;
         Debug.Log(MasterServer.PollHostList().Length);
         hostData = MasterServer.PollHostList();
         }
     }
 }
 
 function OnGUI() {
 if (!Network.isClient && !Network.isServer) {
         if (GUI.Button(Rect(poswidth, posheight, width, height), "Start Server")) {
             Debug.Log("starting server");
             startServer();
         }
         if (GUI.Button(Rect(poswidth, posheight * 1.2 + height, width, height), "Refresh Hosts")) {
             Debug.Log("Refreshing");
             refreshhostlist();
         }
         if (hostData) {
             for(var i : int = 0; i
                 {
 
              Ouch, maybe you could edit your post first and make it more readable.
ya sorry about the messiness when i posted it it got all crunched together and i didn't know how to fix it
you need to use RPC, if youre dealing with sending messages over the network
thanks for the help but i couldn't understand the rpc so i tryed the sendmessage again and i found the problem the ApplyDamage had 2 m's but the health only had 1 anyways when i shoot a object with the script on it it kills everyone anyone know how to fix this.
ps. wil i have to use RPC's for this and if so then how would i go about doing it.
Your answer
 
             Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
C# How to have a gun select 1 Answer
Official Unity Networking example? 0 Answers
UNET Server not setting [SyncVar] 0 Answers
RPC isn't called on objects with another name, even though they have the same script. 1 Answer