Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

i want to call another function from another script but i get NullReferenceException: Object reference not set to an instance of an object

$
0
0
i want to make a 3d quiz game. so I make an inputfield and make a script that randomizes the gameobject spawned. and in the takeText function, I want to take the text in inputField and compare it, if true the gameobject will be setActive(false) and randomize again.this is my keyboard function that take the text from inputField public class KeyboardFunction : MonoBehaviour { public TMP_InputField inputField; public GameObject normalButtons; WordManager wordManager; // Start is called before the first frame update public void InsertChar(string c) { inputField.text += c; } public void DeleteChar() { if(inputField.text.Length > 0) { inputField.text = inputField.text.Substring(0, inputField.text.Length - 1); } } public void TakeText() { string userInput = inputField.text; if(userInput == wordManager.objToSpawn) { Debug.Log("take text"); wordManager.change(); } } } and this is my wordManager script that randomize gameobject by their name. for now I call change function in KeyboarFunction script but I get error NullReferenceException: Object reference not set to an instance of an object in wordManager.change(); from keyboardFunction script. And this is the WordManager script that I want to call the function from public class WordManager : MonoBehaviour { public GameObject[] wordManagers; string[] alphabetChar = new string[] { "A", "B", "C", "D", "E", "F"}; public string objToSpawn; public void Start() { foreach (GameObject Picture in wordManagers) { Picture.gameObject.SetActive(false); } objToSpawn = alphabetChar[Random.Range(0, alphabetChar.Length - 1)]; foreach (GameObject Picture in wordManagers) { if (Picture.name == objToSpawn) { Picture.gameObject.SetActive(true); } } } public void change() { foreach (GameObject Picture in wordManagers) { if (Picture.name == objToSpawn) { Picture.gameObject.SetActive(false); } } objToSpawn = alphabetChar[Random.Range(0, alphabetChar.Length - 1)]; foreach (GameObject Picture in wordManagers) { if (Picture.name == objToSpawn) { Picture.gameObject.SetActive(true); } } } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>