Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Dec 17, 2015 at 05:24 AM by Le-Pampelmuse for the following reason:

Question is outdated.

avatar image
-1
Question by BlackHunter · Jan 02, 2013 at 07:15 AM · guinetworkphoton

NullReferenceException

Please help!

NullReferenceException: Object reference not set to an instance of an object RoomMultiplayerMenu.OnGUI () (at Assets/FPS Kit Version 2.0/_CustomAssets/Scripts/Network C#/RoomMultiplayerMenu.cs:107)

using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Linq; using Random = UnityEngine.Random; using System;

public class RoomMultiplayerMenu : Photon.MonoBehaviour {

 public GUISkin guiSkin;
 public GameObject playerPrefab;
 public GameObject playerPrefab_t;
 public List spawnPoints;
 public List spawnPoints_t;
 public GUIStyle style;
 public Transform BombPlace;
 public string[] maps;
 

 
 [HideInInspector]
 public bool isPaused;
 public bool ct;
 public bool t;
 GameObject enableHelper;
 
 public int TScore;
 public int CTScore;
 

 
 
 ConnectMenu cm;
 bool playerList;
 Resolution[] resolutions;
 string[] QualityNames;
 int resolutionIndex = 3;
 Vector2 scroll;
 Vector2 scroll2;
 Vector2 scroll3;
 
 //Our player spawned
 GameObject Player;
 
 // Use this for initialization
 void Start () {
     cm = GetComponent();
     isPaused = true;
     resolutions = Screen.resolutions;
     resolutionIndex = (resolutions.Length-1)/2;
     QualityNames = QualitySettings.names;
     playerList = true;
     enableHelper = GameObject.FindWithTag("EnableHelper").gameObject;
     ct=false;
         t=false;
 }
 
 // Update is called once per frame
 void Update () {
     
     
     //fps = (int)timer.GetFps();
    
     //timer.Update();
     
     
     if(Input.GetKeyDown(KeyCode.Tab) && Player){
         isPaused = !isPaused;
     }
     /*if(!Player){
         isPaused = true;    
     }*/
     
     if(Input.GetKeyDown(KeyCode.F12)){
         Screen.fullScreen = !Screen.fullScreen;
         if(!Screen.fullScreen){
             Screen.SetResolution(resolutions[resolutionIndex].width, resolutions[resolutionIndex].height, true);
         }
     }
     
     if(isPaused){
         if(enableHelper.active == true){
             enableHelper.active = false;
         }    
         Screen.lockCursor = false;
     }else{
         if(enableHelper.active == false){
             enableHelper.active = true;
         }
         Screen.lockCursor = true;
     }
 }
 
     
 void OnGUI(){
      GUI.Label(new Rect(Screen.width-190, Screen.height-80, 190, 20), " Tab - pause menu", style);
     if(!isPaused)
         return;
     GUI.skin = guiSkin;
     
     GUI.color = new Color(1, 1, 1, 0.7f);
    
     if(isPaused){
         GUI.Window (0, new Rect (Screen.width/2 - 250, Screen.height/2 - 150, 500, 300), MainMenu, "Pause Menu | Room: " + PhotonNetwork.room.name);
         GUI.Window (1, new Rect (Screen.width/2-240, Screen.height/2 - 95, 150, 100), Resolutions, "Resolution");
         GUI.Window (2, new Rect (Screen.width/2-85, Screen.height/2 - 95, 150, 100), QualityWindow, "Quality");
     }
 
 }
 
 void MainMenu (int windowID) {  
     GUILayout.Space (10); 
     GUILayout.BeginHorizontal();
         GUILayout.Box(resolutions[resolutionIndex].width + " x " +  resolutions[resolutionIndex].height, GUILayout.Width(150), GUILayout.Height(25));
         
         GUILayout.Box(QualityNames[QualitySettings.GetQualityLevel ()],   GUILayout.Width(150), GUILayout.Height(25));
     
     
      GUILayout.Space (15); 
         GUILayout.BeginVertical();
             if(!Player){
         
         
         if(ct==true)
         {
             SpawnPlayer();
             t= false;
         }
         else if (t==true)
         {
             SpawnPlayer_t();
             ct = false;
         }
         
         
                 if(GUILayout.Button("Terorist")){
                     isPaused = false;
                     SpawnPlayer_t();
                     t= true;
         }

                             if(GUILayout.Button("CounterTerorist")){
                     isPaused = false;
                     SpawnPlayer();
             ct= true;

} if(GUILayout.Button("Clear Memory")){

                             ct=false;
             t=false;

}

             }else{
                 
         
         
         GUILayout.Space (10); 
         
                                                     if(GUILayout.Button("Clear Memory")){
                     
                     ct=false;
             t=false;

}

                 if(GUILayout.Button("Resume")){
                     isPaused = false;
                 }
             }
             if(GUILayout.Button("Leave Room")){
                 LeaveRoom();
         ct=false;
             t=false;
             }
         GUILayout.EndVertical();
     GUILayout.EndHorizontal();
     
     GUILayout.Space (55);
                 
     //GUILayout.Label("Objective: Have fun :D");
     GUILayout.BeginHorizontal();
         if(playerList){
             GUI.color = new Color(0, 20, 0, 0.6f);
         }else{
             GUI.color = Color.white;
         }
         if(GUILayout.Button("Player List", GUILayout.Width(150), GUILayout.Height(25))){
             playerList = true;
         }
         if(!playerList){
             GUI.color = new Color(0, 20, 0, 0.6f);
         }else{
             GUI.color = Color.white;
         }
         if(GUILayout.Button("Controls", GUILayout.Width(150), GUILayout.Height(25))){
             playerList = false;
         }
     GUILayout.EndHorizontal();
             
     GUILayout.Space (5);
     GUI.color = Color.white;
     scroll3 = GUILayout.BeginScrollView(scroll3, GUILayout.Width(480), GUILayout.Height(100));
         if(!playerList){
             //Show controls

             GUI.color = new Color(20, 20,0, 0.6f);
             GUILayout.Label("Tab - Pause Menu"); 
             GUILayout.Label("F12 - Fullscreen"); 
             GUILayout.Label("T - Chat / Enter - send"); 
             GUILayout.Label("C - crouch");
             GUILayout.Label("Left Ctrl - prone"); 
             GUILayout.Label("LMB - fire"); 
             GUILayout.Label("RMB - aim");
             GUILayout.Label("F - weapon pick up");
             GUILayout.Label("R - reload");
             GUILayout.Label("Left Shift - run");
             GUILayout.Label("Space - jump");
             GUILayout.Label("Q,E - weapon change");
             GUILayout.Label("While selected STW-25 press G for flashlight");

                 
         
         }else{
             //Show player list***
             GUI.color = new Color(1,1,1,0.8f);
             foreach(PhotonPlayer player in PhotonNetwork.playerList){
                 if(PhotonNetwork.player.name == player.name){
                     GUI.color = Color.yellow;
                 }else{
                     GUI.color = Color.white;
                 }
                 GUILayout.BeginHorizontal("box");{
                     GUILayout.Label(player.name, style);
                     if(PhotonNetwork.player.name == player.name){
                         GUILayout.FlexibleSpace();
                         GUILayout.Label("Ping: " + PhotonNetwork.GetPing().ToString(), style);
                     }
                     
                 
                 GUILayout.EndHorizontal();}
             }
         }
     GUILayout.EndScrollView();
 }
 
 void  Resolutions( int windowID){
     GUI.BringWindowToFront(windowID);
     GUILayout.Space (10);
     scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(140), GUILayout.Height(65));
     GUILayout.BeginVertical();
         for(int a = 0; a < resolutions.Length; a++){
             if(resolutions[a].width == Screen.width && resolutions[a].height == Screen.height){
                 GUI.color = new Color(0, 20, 20, 0.6f);
             }else{
                 GUI.color = new Color(20, 20, 20, 0.6f);
             }
             if(GUILayout.Button(resolutions[a].width + " x " + resolutions[a].height)){
                 resolutionIndex = a;
                 if(Screen.fullScreen){
                     Screen.SetResolution (resolutions[resolutionIndex].width,resolutions[resolutionIndex].height, true);    
                 }
             }
         }
     GUILayout.EndVertical();
     GUILayout.EndScrollView();
 }
 
 void QualityWindow(int windowID){
     GUI.BringWindowToFront(windowID);
     GUILayout.Space (10);
     scroll2 = GUILayout.BeginScrollView(scroll2, GUILayout.Width(140), GUILayout.Height(65));
     GUILayout.BeginVertical();
          for (var i = 0; i < QualityNames.Length; i++){
              if(QualityNames[i] == QualityNames[QualitySettings.GetQualityLevel ()]){
                  GUI.color = new Color(0, 20, 20, 0.6f);
              }else{
                  GUI.color = new Color(20, 20, 20, 0.6f);
              }
             if (GUILayout.Button (QualityNames[i]))
                 QualitySettings.SetQualityLevel (i, true);
         }
     GUILayout.EndVertical();
     GUILayout.EndScrollView();
 }
 
 void SpawnPlayer(){
     if(Player){
         Destroy(Player);    
     }
     enableHelper.active = true;
     //Spawn our player
     int temp;
     temp = Random.Range(0, spawnPoints.Count);
     Player = PhotonNetwork.Instantiate(playerPrefab.name, spawnPoints[temp].position, spawnPoints[temp].rotation, 0);
     Player.name = cm.playerName;
     transform.GetChild(0).gameObject.active = false;
 }
     void SpawnPlayer_t(){
     if(Player){
         Destroy(Player);
                     ct=false;
         
         t=true;
     }
     enableHelper.active = true;
     //Spawn our player
     int temp;
     temp = Random.Range(0, spawnPoints_t.Count);
     Player = PhotonNetwork.Instantiate(playerPrefab_t.name, spawnPoints_t[temp].position, spawnPoints_t[temp].rotation, 0);
     Player.name = cm.playerName;
     transform.GetChild(0).gameObject.active = false;

     
 }
 
 void LeaveRoom(){
     if(PhotonNetwork.connected){
         PhotonNetwork.RemoveAllBufferedMessages();
         PhotonNetwork.RemoveRPCs();
         cm.enabled = true;
         cm.connectingToRoom = true;
         cm.fadeDir = -1;
         PhotonNetwork.LeaveRoom();
         this.enabled = false;
         transform.GetChild(0).gameObject.active = true;
         isPaused = false;
         Player = null;
         t=true;
         ct=true;
     }
 }
 
 void OnDisconnectedFromPhoton(){    
     print ("Disconnected from Photon");
     //Something wrong with connection - go to main menu
     cm.enabled = true;
     cm.fadeDir = -1;
     transform.GetChild(0).gameObject.active = true;
     isPaused = false;
     Player = null;
     this.enabled = false;
     t=true;
     ct=true;
 }
 
 
 public void LoadLevel(string level)
 {
     Debug.Log("LoadLevel: " + level);
     PhotonNetwork.isMessageQueueRunning = false;
     Application.LoadLevel(level);
 }


 public void OnLevelWasLoaded(int level)
 {
     Debug.Log(name + " Level Loaded " + level);
     PhotonNetwork.isMessageQueueRunning = true;
 }
 

}

Comment
Add comment · Show 1
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 CodeMasterMike · Jan 02, 2013 at 09:50 AM 5
Share

Please edit your question since it's nearly impossible to see where you error is.

A hint:

Reading the error message, the error is at line 107, (Room$$anonymous$$ultiplayer$$anonymous$$enu.cs:107)

So, ins$$anonymous$$d of a wall of script code that isn't neccessary, post the function where you have the issue (in your case, the OnGUI function) and point out which line is the one which are giving you trouble.

This way is much easier for people to see what you are having trouble with.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I sync Rigidbody2D over the network? 0 Answers

Photon camera problum 0 Answers

why can not I put something on the scene in a prefab? 1 Answer

Network lobby manager tutorial +PUN? 0 Answers

Photon - Enable MouseLook Script from First Person Controller? 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