To the awesome Unity Forums community,
OVERVIEW:
I have a list in a script:
public class AlphaSpawner2 : MonoBehaviour
public List Alpha2 = new List();
and this list when started has the values of the alphabet
void Start()
{
for (char letter = 'A'; letter <= 'Z'; letter++)
{
Alpha2.Add(letter.ToString());
}
}
**ERROR:**
Now basically these values are used to be displayed on text ui element.
I want to be able to retrieve the value from the text (in another script) and be able to find the index of the element.
public class Checker2 : MonoBehaviour {
public void CountChecker()
{
Debug.Log("Checking...");
GameObject other = GameObject.Find("AOBDT");
AlphaSpawner2 alphaSpawner2 = other.GetComponent();
Text myText = gameObject.GetComponentInChildren();
char Indexfinder =char.Parse(myText.text);
Debug.Log(Indexfinder);
int CorrectNum2 = alphaSpawner2.Alpha2.IndexOf(Indexfinder.ToString()) + 1; // this line of code is where the error is at
Debug.Log("Real Number:" + CorrectNum2);
**Error displayed in console:**
NullReferenceException: Object reference not set to an instance of an object
Checker2.CountChecker () (at Assets/Scripts/CountingUp/Infinity/Checker2.cs:43)
Checker2.OnMouseDown () (at Assets/Scripts/CountingUp/Infinity/Checker2.cs:30)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)
Any help is greatly appreciated. Many huge thanks in advance for reading this.
↧