Author Topic: How to get multiple input values ?  (Read 3629 times)

abclive

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
How to get multiple input values ?
« on: June 17, 2013, 12:23:54 PM »
Hi everybody !

Today I tried to get multiples values from differents input by using a single script. But I have a "NullReferenceException: Object reference not set to an instance of an object". So I though that I could ask your help.

So here is my script :

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [RequireComponent(typeof(UIInput))]
  5. [AddComponentMenu("/Scripts/MenuManager")]
  6. public class MenuManager : MonoBehaviour {
  7.        
  8.         public MenuManager instance;
  9.        
  10.         public UIInput slots;
  11.         public UIInput matchname;
  12.  
  13.         public string CurrentMenu;
  14.         public string MatchName = "";
  15.         public string MatchPassword = "";
  16.         public int MatchMaxPlayers = 32;
  17.         private string iptemp = "127.0.0.1";
  18.        
  19.         private Vector2 ScrollLobby = Vector2.zero;
  20.        
  21.         void Start(){
  22.                
  23.                 instance = this;
  24.                 slots = GetComponent<UIInput>();
  25.                 matchname = GetComponent<UIInput>();
  26.                 //CurrentMenu = "Main";
  27.         }
  28.        
  29.         void Update(){
  30.                 MatchName = matchname.text;
  31.                 int SlotNumber = int.Parse(slots.text);
  32.                 MatchMaxPlayers = SlotNumber;
  33.         }
  34.        
  35.         void FixedUpdate(){
  36.                 instance = this;       
  37.         }
  38. }

This has been written with the Unity GUI based system so there is some thing which don't belong here but please don't care about it.

The error is on this line :

MatchName = matchname.text;

Here's a screen of my settings : http://d.pr/i/GWZ2

I hope that you could help me resolving this problem :) Thank you in advance and apologize for my bad english.

abclive

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: How to get multiple input values ?
« Reply #1 on: June 17, 2013, 05:09:57 PM »
Okay I understood something, my start function is reseting values, how to fix that ?

abclive

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: How to get multiple input values ?
« Reply #2 on: June 17, 2013, 05:11:13 PM »
Okay just removing them ...