hello there , i making a Question and answer game in unity , but i get this problem whenever i try to check for the correct response , i have three scripts, the first one game_uGUI which basically set the questions and answers from the files , the second is call_win and the third is call_lose.
i have four buttons in the scene and everything is attached to its place scripts and everything
but one i test, it gives back :
NullReferenceException: Object reference not set to an instance of an object
game_uGUI.button_two_logic () (at Assets/mobile game menu kit/script/game_scene/game_uGUI.cs:414)
maybe my approach here is causing the problem as i am calling onMousDown() from both call_win& call_lose.
this is game_uGUI script
public void button_four_logic()
{
if (response_4.text.CompareTo(correct_rsp) == 0)
{
call_win.OnMouseDown();
}
else
call_lose.OnMouseDown();
}
public void button_one_logic()
{
if (response_1.text.CompareTo(correct_rsp) == 0)
{
call_win.OnMouseDown();
}
else
call_lose.OnMouseDown();
}
public void button_two_logic()
{
if (response_2.text.CompareTo(correct_rsp) == 0)
call_win.OnMouseDown();
else
call_lose.OnMouseDown();
}
public void button_three_logic()
{
if (response_3.text.CompareTo(correct_rsp) == 0)
{
call_win.OnMouseDown();
}
else
call_lose.OnMouseDown();
}
this is call_win script
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class call_win : MonoBehaviour {
public int star_score;
game_uGUI my_game_uGUI;
public int score;
public Text pscore;
void Start()
{
my_game_uGUI = GameObject.FindGameObjectWithTag("_gui_").GetComponent<game_uGUI>();
}
public void OnMouseDown ()
{
if (!game_uGUI.in_pause)
{
my_game_uGUI.star_number = star_score;
pscore.text = "100";
my_game_uGUI.Victory();
}
}
}
this is the call_lose script:
using UnityEngine;
using System.Collections;
public class call_lose : MonoBehaviour {
game_uGUI my_game_uGUI;
void Start()
{
my_game_uGUI = GameObject.FindGameObjectWithTag("_gui_").GetComponent<game_uGUI>();
}
public void OnMouseDown ()
{
if (!game_uGUI.in_pause)
{
my_game_uGUI.Defeat();
}
}
}