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 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.

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

Help with photon being used to make a mulitplayer fps 0 Answers

[Help!] Showing only your health in a Multiplayer FPS game 0 Answers

Networking Fps Cameras 0 Answers

MultiplayerFPS - database error 1 Answer


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