Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Network Shoot/health script

$
0
0
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 {

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>