My goal is: Type into the input field → press the button “Enter” → have that added to the drop down list.
My question is → How do I get rid of this NullReferenceException Error?
And if at all possible, how can I make this work?
The Error I am getting is this.
NullReferenceException: Object reference not set to an instance of an object
DdMenu.addItem()(at Assets/Scripts/DdMenu.cs: 20)
Here are my two scripts.
First script : This is for adding the options into the dropdown menu
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DdMenu : MonoBehaviour {
AddOption ao;
public Text selectedName;
public Dropdown drop;
public void dropIndex(int varIndex){
selectedName.text = ao.menuList[varIndex];
}
public void addItem(){
drop.AddOptions (ao.get_holder()); //Error is here
}
}
Second Script: This is for getting the text from the input field.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AddOption : MonoBehaviour {
public List<string> menuList;
public Text test;
private string x;
public void getText(){
x = test.text;
menuList.Insert (0, x);
}
public List<string> get_holder(){
return menuList;
}
}