Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ZurielB · Jan 03, 2018 at 06:01 AM · networkingfpsserverdamage

[FPS Multipler] Host only one that can kill.

Not sure if my post got posted. If it didn't here question. I am working on an Multiplayer fps and having some problems. I am currently using the Unity server, and having the problem of the host been the only one to kill a player. I having been looking at tutorials, and It's the first time I working with the multiplayer area. Here is my health code. I don't know if its my code or am I missing something.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class Health : NetworkBehaviour {
 
     [SerializeField]
     public const int maxHealth = 100;    //Heath of Iteam
 
     [SyncVar] 
     public int currentHealth = maxHealth;
 
     private NetworkStartPosition[] spawnPoints;
 
     void Start (){
         if (isLocalPlayer){
             spawnPoints = FindObjectsOfType<NetworkStartPosition>();
         }
     }
 
     public void TakeDamage (int amount){
 
         if(!isServer){
             return;
         }
 
         //Subtracts the amount(damage) from health
         currentHealth -= amount;
 
         //Checks if health is less than 0 to kill object
         if(currentHealth <= 0){
             currentHealth = maxHealth;

 
             RpcRespawn();
         }
     }
 
     [ClientRpc]
     void RpcRespawn(){
         
         if (isLocalPlayer){
             // Set the spawn point to origin as a default value
             Vector3 spawnPoint = Vector3.zero;
 
             // If there is a spawn point array and the array is not empty, pick one at random
             if (spawnPoints != null && spawnPoints.Length > 0)
             {
                 spawnPoint = spawnPoints[Random.Range(0, spawnPoints.Length)].transform.position;
             }
 
             // Set the player’s position to the chosen spawn point
             transform.position = spawnPoint;
         }
     }
 }
 

This is my Gun Script.

 using UnityEngine;
 
 public class Gun : MonoBehaviour {
 
     public float damage = 25f;    //Damage for gun
     public int damagePlayer = 10;
     public float range = 100f;    //Range for gun
     public float forceAdded;
 
     public ParticleSystem muzzleFlash; //Particle for the muzzle flash
      
     public Camera fpsCam;    //Camera
 
     // Update is called once per frame
     void Update () {
 
         if(Input.GetButtonDown("Fire1")){
             Shoot();
         }
     }
 
     void Shoot (){
         RaycastHit hit;
         if(Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)){
             //Plays the Muzzle Flash
             muzzleFlash.Play();
 
             //Debug.Log(hit.transform.name);
 
             Health health = hit.transform.GetComponent<Health>();
 
             //Checks if anything was hit
             if (health != null){
                 //Calls the Target script to add damage to the oject hitted.
                 health.TakeDamage(damagePlayer);
             } 
 
             //Get whatever was hit
             Target target = hit.transform.GetComponent<Target>();
 
             //Checks if anything was hit
             if (target != null){
                 //Calls the Target script to add damage to the oject hitted.
                 target.TakeDamage(damage);
             } 
 
             //This give a force to anything the bullet hits
             if (hit.rigidbody != null){
                 hit.rigidbody.AddForce(-hit.normal * forceAdded);
             }
         }
     }
 }

This is a link to download version to my game. If it helps. https://gamejolt.com/games/ai/308730 I have been mainly following the Unity Basic Multiplayer Tutorial. Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

181 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UDPClient can't receive and send ? 0 Answers

NetworkManager how StartMatchMaker works? ListMatches not getting my server. 0 Answers

Looking for a Simple MultiPlayer Server 0 Answers

Need help spawning a gameObject on the server UNET 1 Answer

Getting the time from a server 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges