• 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 $$anonymous$$ · Sep 05, 2017 at 07:37 PM · unity 5error

Object reference not set to an instance of an Object Error

So i am doing this script, and get this error ,help me please;

here is the script

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 using System.Collections.Generic;
 using UnityEngine.UI;
 
 
 
 using Hashtable = ExitGames.Client.Photon.Hashtable;
 
 public class RigidbodyFPSWalker : MonoBehaviour
 {
 
 
     public float speed = 10.0f;
     public float gravity = 10.0f;
     public float maxVelocityChange = 10.0f;
     public bool canJump = true;
     public float jumpHeight = 2.0f;
     private bool grounded = false;
     public PhotonView name;
 
     public string theKiller = "";
     public string killerWep = "";
 
     public GameObject me;
     public GameObject graphics;
     public GameObject ragDoll;
 
     public int health = 100;
 
     public GameObject fpsCam;
 
     public bool isPause = false;
 
     public AudioSource sound1;
 
     public AudioClip soundClip;
 
     private GUIStyle guiStyle = new GUIStyle();
 
     //kills
     public int kills = 0;
     //mortes
     public int deaths = 0;
 
 
     void Start()
     {
 
 
         GetComponent<Rigidbody>().freezeRotation = true;
         GetComponent<Rigidbody>().useGravity = false;
         name.RPC("updateName", PhotonTargets.AllBuffered, PhotonNetwork.playerName, health);
         gameObject.name = PhotonNetwork.playerName;
 
 
 
     }
 
 
 
     void FixedUpdate()
     {
 
         kills = PlayerPrefs.GetInt("kills");
         deaths = PlayerPrefs.GetInt("deaths");
 
 
         if (grounded)
         {
 
             // Calculate how fast we should be moving
             Vector3 targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
             targetVelocity = transform.TransformDirection(targetVelocity);
             targetVelocity *= speed;
 
             // Apply a force that attempts to reach our target velocity
             Vector3 velocity = GetComponent<Rigidbody>().velocity;
             Vector3 velocityChange = (targetVelocity - velocity);
             velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
             velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
             velocityChange.y = 0;
             GetComponent<Rigidbody>().AddForce(velocityChange, ForceMode.VelocityChange);
 
             // Jump
             if (canJump && Input.GetButton("Jump"))
             {
                 GetComponent<Rigidbody>().velocity = new Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
             }
 
 
         }
 
         if (Input.GetKeyDown(KeyCode.Q))
         {
             isPause = true;
 
         }
         if (Input.GetKeyUp(KeyCode.Q))
         {
             isPause = false;
         }
 
 
         if (Input.GetKey(KeyCode.Escape))
         {
             Application.Quit();
 
         }
 
         // We apply gravity manually for more tuning control
         GetComponent<Rigidbody>().AddForce(new Vector3(0, -gravity * GetComponent<Rigidbody>().mass, 0));
 
         grounded = false;
 
         if (health <= 0)
         {
             GetComponent<PhotonView>().RPC("DIE", PhotonTargets.AllBuffered, null);
         }
 
     }
 
 
 
     void OnCollisionStay()
     {
         grounded = true;
     }
 
     float CalculateJumpVerticalSpeed()
     {
         // From the jump height and gravity we deduce the upwards speed 
         // for the character to reach at the apex.
         return Mathf.Sqrt(2 * jumpHeight * gravity);
     }
 
     /*
         void OnGUIStop(){
             GUI.color = Color.red;
             GUI.Box (new Rect (100, 10, 100, 30), "HP | " + health);
 
             if (isPause) {
                 GUILayout.BeginArea (new Rect(Screen.width/2 - 250, Screen.height/2 - 250, 500,500));
 
                 foreach (var teamName in PunTeams.PlayersPerTeam.Keys)
                 {
                     GUILayout.Label("Team: " + teamName.ToString());
                     List<PhotonPlayer> teamPlayers = PunTeams.PlayersPerTeam[teamName];
                     foreach (PhotonPlayer player in teamPlayers)
                     {
                         GUILayout.Label("  " + player.ToStringFull() + " Score: " + player.GetScore());
                     }
                 }
                 GUILayout.EndArea ();
             }
         }
     */
 
 
 
 
     public void getClip(AudioClip soundToRecieve)
     {
         Debug.Log(soundToRecieve.name);
         soundClip = soundToRecieve;
     }
 
 
 
     [PunRPC]
     public void applyDamage(int dmg, string killerName, string wepName)
     {
         health = health - dmg;
         name.RPC("updateName", PhotonTargets.AllBuffered, PhotonNetwork.playerName, health);
         theKiller = killerName;
         killerWep = wepName;
         Debug.Log("hit!" + health);
     }
 
 
 
     [PunRPC]
     public void DIE()
     {
         if (GetComponent<PhotonView>().isMine)
         {
 
             PhotonNetwork.Destroy(me);
             Destroy(me);
 
             ragDoll = PhotonNetwork.Instantiate(ragDoll.name, transform.position, transform.rotation, 0);
             ragDoll.GetComponent<Rigidbody>().AddForce(transform.forward, ForceMode.Force);
             Destroy(ragDoll, 1);
 
             PlayerPrefs.SetInt("deaths", deaths + 1);
 
             GameObject.Find("_ROOM").GetComponent<lobbyManager>().OnJoinedRoom();
             GameObject.Find("_NetworkScripts").GetComponent<PhotonView>().RPC("addFeed", PhotonTargets.All, theKiller + " [" + killerWep + "] " + PhotonNetwork.playerName);
 
 
             /*
             foreach (var teamName in PunTeams.PlayersPerTeam.Keys) {
 
                 List<PhotonPlayer> teamPlayers = PunTeams.PlayersPerTeam [PunTeams.Team.red];
                 foreach (PhotonPlayer player in teamPlayers) {
                     GameObject.Find ("_NetworkScripts").GetComponent<PhotonView>().RPC ("addFeed", PhotonTargets.All, theKiller + " [" + killerWep + "] " + PhotonNetwork.playerName);
                     GameObject killer2 = GameObject.Find (theKiller);
                     killer2.GetComponent<PhotonView>().RPC ("addKill", PhotonTargets.AllBuffered, null);
                     killer2.GetComponent<PhotonView>().RPC ("exitTrig", PhotonTargets.AllBuffered, null);
                     GameObject.Find ("_ROOM").GetComponent<lobbyManager> ().teamRed ();
                     return;
                 }
 
             }
 */
 
             /*
             foreach (var teamName2 in PunTeams.PlayersPerTeam.Keys) {
 
                 List<PhotonPlayer> teamPlayers2 = PunTeams.PlayersPerTeam[PunTeams.Team.blue];
                 foreach (PhotonPlayer player2 in teamPlayers2) {
                     GameObject.Find ("_NetworkScripts").GetComponent<PhotonView>().RPC ("addFeed", PhotonTargets.All, theKiller + " [" + killerWep + "] " + PhotonNetwork.playerName);
                     GameObject.Find ("_ROOM").GetComponent<lobbyManager> ().teamBlue ();
 
                 }
             }
 */
             GameObject killer2 = GameObject.Find(theKiller);
             print("gameObejct " + killer2);
             killer2.GetComponent<PhotonView>().RPC("addKill", PhotonTargets.AllBuffered, null);
             killer2.GetComponent<PhotonView>().RPC("exitTrig", PhotonTargets.AllBuffered, null);
 
         }
 
 
     }
 
     [PunRPC]
     public void addKill()
     {
 
         PlayerPrefs.SetInt("kills", kills + 1);
 
     }
 
     void OnTriggerEnter(Collider other)
     {
 
         if (other.tag == "life")
         {
             int upgrade_health = 50;
             health += upgrade_health;
         }
     }
 
 
 
     public AudioClip[] sounds;
 
 
     [PunRPC]
     public void playSound()
     {
         Debug.Log("Sound: " + soundClip.name);
         sound1.PlayOneShot(soundClip);
     }
 
     void OnGUI()
     {
         guiStyle.fontSize = 40;
         GUI.color = Color.green;
         GUI.Label(new Rect(200, 850, 150, 30), "" + health, guiStyle);
 
         if (isPause)
         {
             GUILayout.BeginArea(new Rect(Screen.width / 2 - 250, Screen.height / 2 - 250, 500, 500));
             GUILayout.Box("Score:" + "\nKills: " + kills + " / " + "Deaths: " + deaths);
             GUILayout.Box("Players:    Name         K/D   ");
             foreach (PhotonPlayer pl in PhotonNetwork.playerList)
             {
                 GUILayout.Box(pl.name + " | " + pl.GetScore());
             }
             GUILayout.EndArea();
         }
 
     }
 
 }

Comment
Add comment · Show 6
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 lorenzofman2 · Sep 09, 2017 at 10:48 PM 0
Share

Can you copy the full error line? So we can track faster where the error is?

avatar image $$anonymous$$ · Sep 09, 2017 at 10:55 PM 0
Share

In the void die in the gameobject killer

avatar image $$anonymous$$ · Sep 09, 2017 at 10:55 PM 0
Share

The error os on the title of this post

avatar image lorenzofman2 $$anonymous$$ · Sep 10, 2017 at 02:10 AM 0
Share

Your errors tells that the object that you're referencing it's not set. Probably your code is not finding the killer by his name. I would suggest to check if it's name matches with the object you're trying to get. Also check if this "killer" that you get with the "$$anonymous$$iller name" have the PhotonView you're getting in it's root.

avatar image Cuttlas-U · Sep 10, 2017 at 07:18 AM 0
Share

hi; ok thats a huge code right there; do u really want me to read it all ? pls send me the lane that the error is happening and showing in console;

avatar image $$anonymous$$ · Sep 10, 2017 at 08:47 AM 0
Share

Line 231 on method rpc add kill

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

199 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 avatar image avatar image avatar image avatar image avatar image avatar image 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

ComponentChunkIterator is not liking me.. 0 Answers

Missing the class attribute 'ExtensionOfNativeClass' 4 Answers

how to fix automatic camera rotation when using joysticks? 0 Answers

Error in Inventory Script 1 Answer

I need help with a error: APIUpdaterRuntimeServices 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