I’m trying to build a ‘monthly event’ system for my management game and it keep on throwing up the Object reference not set to an instance of an object issue on line 19, but only when the event occurs. The events are called from another script, and yes, I know it’s a hideous mess but I haven’t worked out how to optimise it yet. So, any help or guidance would be very much appreciated?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System;
public class EventManager : MonoBehaviour {
GameObject PopupWindow;
Text PopupText;
int RndEvent;
int populationlvl;
int nextintake;
public static void EventOccurer(){
GameObject PopupWindow = GameObject.FindGameObjectWithTag("PopupWindow");
int RndEvent;
int populationlvl;
int nextintake;
Text PopupText = GameObject.Find("EventMessageText").GetComponent<UnityEngine.UI.Text> ();
PopupWindow.SetActive (true);
RndEvent = UnityEngine.Random.Range (1, 13);
switch (RndEvent)
{
case 1:
PopupText.text = "Launch Failure! Loss of next intake!";
populationlvl = WorldManager.PopulationLvl;
nextintake = WorldManager.PopIntake;
populationlvl -= nextintake;
WorldManager.PopulationLvl = populationlvl;
break;
case 2:
PopupText.text = "Landing Failure! Loss of next intake!";
populationlvl = WorldManager.PopulationLvl;
nextintake = WorldManager.PopIntake;
populationlvl -= nextintake;
WorldManager.PopulationLvl = populationlvl;
break;
case 3:
break;
//.....A whole lot of currently empty case statements...
case 12:
break;
}
}
}