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 /
avatar image
0
Question by Rtsgamerx · Mar 10, 2019 at 12:34 PM · networkingbugupdate

Script acting weirdly after updating from 2018.2.2 to 2018.3.1

Everything was working fine util I updated to Unity 2018.3.1. Here you can see my player script. The problem is when a player die, he dies on the instance of the player who kills him, but is still alive in his instance. And when he respawns he sometimes respawn with over 100 hp or less.This scripts is attached to the player with a networkIdentity:

     using UnityEngine;
     using UnityEngine.Networking;
     using System.Collections;
     public class Player : NetworkBehaviour {
         public int MaxHealth = 100;
       [SyncVar]
         private bool _isDead = false;
         public bool isDead
         {
             get { return _isDead; }
             protected set { _isDead = value; }
         }
         [SerializeField]
         private Behaviour[] DisableOnDeath;
         [SerializeField]
         private GameObject[] DisableGameObjectsOnDeath;
         private bool[] wasenabled;
         public void PlayerSetup() {
     wasenabled = new bool[DisableOnDeath.Length];
             for (int i = 0; i < wasenabled.Length; i++)
             {
                 wasenabled[i] = DisableOnDeath[i].enabled;
     
             }
             SetDefaults();
         }
         public void SetDefaults()
         {
             isDead = false;
             CurrentHealth = MaxHealth;
             for (int i = 0; i < DisableOnDeath.Length; i++)
             {
                 DisableOnDeath[i].enabled = wasenabled[i];
             }
             //Enable GameObjects
             for (int i = 0; i < DisableGameObjectsOnDeath.Length; i++)
             {
                 DisableGameObjectsOnDeath[i].SetActive(true);
             }
             Collider col = GetComponent<Collider>();
             if (col != null)
             {
                 col.enabled = true;
             }
             Playerui.SetActive(true);
             //Make SpawnEffect  
                     GameObject gfxIns = Instantiate(SpawnEffect, transform.position, Quaternion.identity);
                    Destroy(gfxIns, 3f);
                 
         }
     [ClientRpc]
         public void RpcTakeDamage(int amount)
         {
             if (isDead)
                 return;
             CurrentHealth -= amount;
             Debug.Log(transform.name + " has now " + CurrentHealth + " health");
             if (CurrentHealth <= 0)
             {
                 Die();
             }
         }
         IEnumerator Respawn()
         {
             yield return new WaitForSeconds(GameManager.instance.matchSettings.RespawnDelay);
             Transform _startpoint = NetworkManager.singleton.GetStartPosition();
             transform.position = _startpoint.position;
             transform.rotation = _startpoint.rotation;
             yield return new WaitForSeconds(0.1f);
             SetDefaults();
             Debug.Log(transform.name + " Respawned");
         }
     public void Die()
         {
             isDead = true;
     
             //DisableComponenents
             for (int i = 0; i < DisableOnDeath.Length; i++)
             {
                 DisableOnDeath[i].enabled = false;
             }
             //DisableGameObjects
             for (int i = 0; i < DisableGameObjectsOnDeath.Length; i++)
             {
                 DisableGameObjectsOnDeath[i].SetActive(false);
             }
             //Disable the collider
             Collider col = GetComponent<Collider>();
             if (col != null)
             {
                 col.enabled = false;
             }
             Playerui.SetActive(false);
             Debug.Log(transform.name + " is dead");
              //SpawnDeathEffect
             GameObject gfxIns = Instantiate(deathEffect, transform.position, Quaternion.identity);
             Destroy(gfxIns, 3f);
             //Call respawn method;
             StartCoroutine(Respawn());
             }}

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

154 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

Related Questions

UNET "no free events for message" when client pauses game. 2 Answers

Threading with UDPClient - Editor Freezing 2 Answers

Network.Connect Fails To Connect 0 Answers

[UNET] Raycast Update lag when Client connect 1 Answer

Unity networking tutorial? 6 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