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 adipatil3517 · May 15, 2017 at 11:35 AM · c#networkingnull reference exception

Why my networked client Player is not dying ??

following is my code:-

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.Networking;
 public class Health : NetworkBehaviour
 {
 
 public const int maxhealth = 100;
 public int Value = 10;
 [SyncVar(hook = "OnChangeHealth")] public int currhealth = maxhealth;
 public bool  DestroyOnDeath;
 public RectTransform healthBar;


 // Use this for initialization
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {
     
 }

 public void takeDamage(int amount)
 {


     if (DestroyOnDeath)
     {
         
         //Debug.Log ("Hii");

         //Debug.Log ("Hello");    
         Destroy(gameObject);


         int respawn = GetComponent<EnemySpawner> ().noOfEnemy;
         if (respawn == 0) {
             GetComponent<EnemySpawner> ().OnStartServer ();
         }
     }
     else
     {
         currhealth -= amount;
         if (currhealth <= 0)
         {
             AudioSource dead = GetComponent<AudioSource> ();
             dead.Play ();
             currhealth = maxhealth;
             RpcRespawn();
         }
     }

 }

 void OnChangeHealth(int health)
 {
     healthBar.sizeDelta = new Vector2(health * 2, healthBar.sizeDelta.y);
 }

 [ClientRpc]

 void RpcRespawn()

 {
     if(!isLocalPlayer)
     {
         transform.position = Vector3.zero;
     }
     
 }

}

Using this code My zombie kill player in scene and move to next player but after kill first player sometimes he kill other player sometime gives exception now i dont understand why it is happing please help me

the error is as follow :-

 NullReferenceException: Object reference not set to an instance of an object
 Health.takeDamage (Int32 amount) (at Assets/Standard Assets/Script/Health.cs:41)
 ZombieAttack.CheckIfTargetInRange () (at Assets/Standard Assets/Script/ZombieAttack.cs:43)
 ZombieAttack+c__Iterator0.MoveNext () (at Assets/Standard Assets/Script/ZombieAttack.cs:52)
 UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

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 thornekey · May 15, 2017 at 01:50 PM 0
Share

it says why it is happening. Object reference not set to an instance of an object. the object reference is not set.

avatar image adipatil3517 thornekey · May 16, 2017 at 06:31 AM 0
Share

But i set the object reference i dot understand why it is not taking the reference actually sometimes it take Reference sometime it won't

avatar image thornekey · May 16, 2017 at 09:48 AM 0
Share

perhaps its being set only on one client

avatar image adipatil3517 thornekey · May 16, 2017 at 10:23 AM 0
Share

hello friend, Actually i started making ga$$anonymous$$g watching unitys multiplayer game tutorial which contain 18 tutorials. now that was finished and i wanted to make enemy follow player and kill him. and i found another tutorial series which contain Enemy following Player and $$anonymous$$illing player.but the thing is both tutorials are different and both have different techniques used now i m stuck because i dont understand where and how to apply changes. i understood what is the problem but dont know how to solve it. Its actually health Script problem.

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

91 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

[UNET] Only spawn certain server objects on local client? 0 Answers

C# How to have a toggle 1 Answer

Network how to send data/activate function 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