• 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 Mansmart10 · Oct 22, 2016 at 01:00 AM · multiplayerfpshealth

How do i fix a multiplayer fps health issue?

Im making a multiplayer game and when i host a game i could kill the other player but the other player can't kill the host. I have a health script that works for the host but not the client, but when i turn off the health, and uncomment out this line ("CmdHitPlayer(hit.transform.gameObject);")the other player can now kill the host no problem.

Health Script: using UnityEngine; using UnityEngine.Networking;

public class Health : NetworkBehaviour { //The box's current health point total public const int maxHealth = 100; [SyncVar] public int currentHealth = maxHealth;

 public void Damage(int damageAmount)
 {
     if (!isServer)
     {
         return;
     }
     //subtract damage amount when Damage function is called
     currentHealth -= damageAmount;

     //Check if health has fallen below zero
     if (currentHealth <= 0)
     {
         //Destroy(gameObject);
         //if health has fallen below zero, deactivate it 
         CmdHitPlayer(transform.gameObject);
         currentHealth = maxHealth;
     }
 }

 [Command]
 void CmdHitPlayer(GameObject hit)
 {
     hit.GetComponent<NetworkedPlayerScript>().RpcResolveHit();
 }

}

Shooting Script: using UnityEngine; using UnityEngine.Networking;

public class ShootingScript1 : NetworkBehaviour { public ParticleSystem _muzzleFlash; public AudioSource _gunAudio; public GameObject _impactPrefab; public Transform cameraTransform;

 ParticleSystem _impactEffect;

 public int gunDamage = 25;
 public float range;
 public float fireRate;


 void Start()
 {
     _impactEffect = Instantiate(_impactPrefab).GetComponent<ParticleSystem>();
 }

 void Update()
 {
     //if (Input.GetButtonDown("Fire2"))
         //CmdHitPlayer(gameObject);

     if (Input.GetButtonDown("Fire1"))
     {
         _muzzleFlash.Stop();
         _muzzleFlash.Play();
         _gunAudio.Stop();
         _gunAudio.Play();

         RaycastHit hit;
         Vector3 rayPos = cameraTransform.position + (1f * cameraTransform.forward);

         if (Physics.Raycast(rayPos, cameraTransform.forward, out hit, range))
         {
             Health health = hit.transform.GetComponent<Health>();
             _impactEffect.transform.position = hit.point;
             _impactEffect.Stop();
             _impactEffect.Play();

             if (hit.transform.tag == "Player")
             {
                 health.Damage(gunDamage);
                 //CmdHitPlayer(hit.transform.gameObject);
             }
         }
     }
 }

 /*[Command]
 void CmdHitPlayer(GameObject hit)
 {
     hit.GetComponent<NetworkedPlayerScript>().RpcResolveHit();
 }*/

}

Comment
Add comment · Show 4
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
avatar image Mike-Geig ♦♦ · Oct 22, 2016 at 06:40 PM 0
Share

You deleted the other post where I answered your question... Not sure why you did that but it doesn't exactly encourage anyone to continue helping.

avatar image Mansmart10 Mike-Geig ♦♦ · Oct 22, 2016 at 06:57 PM 0
Share

Sorry but i had that post up for a few days now and no one was helping. I been having the problem for a week now and i cant find a solution. So i deleted it and changed it to put it in the help room.

avatar image Mike-Geig ♦♦ Mansmart10 · Oct 24, 2016 at 02:54 AM 0
Share

I gave you the answer already. And you responded that you found your answer. What happened?

Show more comments

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

113 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

Related Questions

Client can damage host but not vice versa? 0 Answers

Raycast over Photon 0 Answers

Healthbar in a Multiplayer game 0 Answers

How to make a map voting system 1 Answer

Syncing a prefab color on all clients Uweb 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges