Unity quest system a better way?
Hello here is my code it is many variables and if-statments. I wondered if it were a better way of doing it. It is getting hard to have that type of system and find things with many variables and if-statments. Hope you can help :)
#pragma strict
public var text : String = "";
public var text2 : String = "";
public var text3 : String = "";
public var text4 : String = "";
public static var SpidersKilled : int;
public static var Crates : int;
public static var BanditsKilled : int;
public static var Empty2 : int;
public static var PosText1 : int = 140;
public static var PosText2 : int = 240;
public static var PosText3 : int = 340;
public static var PosText4 : int = 440;
public static var HasDoneQuest1 : boolean = false;
public static var HasDoneQuest2 : boolean = false;
public static var HasDoneQuest3 : boolean = false;
public static var HasDoneQuest4 : boolean = false;
public static var Ree1 : boolean = false;
public static var Ree2 : boolean = false;
public static var Ree3 : boolean = false;
public static var QuestActive1 : boolean = false;
public static var QuestActive2 : boolean = false;
public static var QuestActive3 : boolean = false;
public static var QuestActive4 : boolean = false;
function Update ()
{
if(HasDoneQuest1 == true && Ree1 == false)
{
PosText2 -= 100;
PosText3 -= 100;
PosText4 -= 100;
Ree1 = true;
}
if(HasDoneQuest2 == true && Ree2 == false)
{
PosText3 -= 100;
PosText4 -= 100;
Ree2 = true;
}
if(HasDoneQuest3 == true && Ree3 == false)
{
PosText4 -= 100;
Ree3 = true;
}
//Quest 1
if(QuestActive1 == true)
{
text = "Economic trouble: Hello, the spiders in the mine prevent us from gather the riches. Without it our economy is ruined, could you kill 4 spiders? Spiders killed: " + SpidersKilled;
}
//Quest 2
if(QuestActive2 == true)
{
text2 = "The robbery: Last night some bandits came and robbed the food storage, could you get the 4 crates of food back? Crates" + Crates;
}
//Quest 3
if(QuestActive3 == true)
{
text3 = "The bandits in the woods:" + BanditsKilled;
}
//Quest 4
if(QuestActive4 == true)
{
text4 = "" + SpidersKilled;
}
//Quest done 1
if(QuestActive1 == false)
{
text = "";
}
//Quest done 2
if(QuestActive2 == false)
{
text2 = "";
}
//Quest done 3
if(QuestActive3 == false)
{
text3 = "";
}
//Quest done 4
if(QuestActive4 == false)
{
text4 = "";
}
}
function OnGUI ()
{
if(Input.GetKey(KeyCode.Tab))
{
GUI.Box(Rect (10,140,400,360),"");
GUI.Label (Rect (10,PosText1,400,360), "" + text);
GUI.Label (Rect (10,PosText2,400,360), "" + text2);
GUI.Label (Rect (10,PosText3,400,360), "" + text3);
GUI.Label (Rect (10,PosText4,400,360), "" + text4);
}
}
Answer by WinterstoneStudios · Jan 20, 2016 at 07:06 PM
I tried using Arrays and inheritance, but i got a error that says it don't got a visible constructor that matches the arguement list String[] The error is in the script "QuestLager". Here is the code:
pragma strict
public class QuestFabrikk { public var Quests : String[]; public var Booleans : Boolean[]; public var Ints : int[]; public var Position : int[];
public function Quest()
{
Quests[0] = "";
Debug.Log("1st Fruit Constructor Called");
}
//This is the second constructor for the Fruit class
//and is not inherited by any derived classes.
public function Quest(newQuests : String[])
{
Quests = newQuests;
Debug.Log("2nd Fruit Constructor Called");
}
public function GetQuest()
{
Debug.Log("The fruit has been chopped." + Quests[0] );
}
public function SayHello()
{
Debug.Log("Hello, I am a fruit.");
}
function Start () {
}
function Update () {
}
}
pragma strict
public var Quests : String[]; var Quest1 = new Quest(Quests[0]);
function Start () {
}
function Update () {
}
Your answer
Follow this Question
Related Questions
Problem while using several tags in a OnTriggerEnter (Collider other) 0 Answers
If statement unexpectedly changing value. 0 Answers
Referencing variables in another script on the same game object 0 Answers
Need a object to react different when clicked mutliple times 1 Answer
RaycastHit2D ground detection 1 Answer