Personally I’d make use of a few things unity has to offer.
Firstly I’d make an npc script which has variables you can assign in the playerprefs. For example, if say i was doing an RPG and i wanted to kill a wolf enemy, I’d make a singleton that returned a count to the npc script im making, but one. IE when the quest script is active and the playerpref which is assigned to it, for each time a wolf dies the script will go up.
Let me explain this in detail as I myself took almost a year to work this out as i couldn’t find anything to help me:
So you first want to make a general Enemy class, this holds info like health ect, except make this hold the values for each animal ingame, with this base class, you can assign what a wolf is ect, were you might put a public bool on the script so in the inspector you can just drag to wolf, tick the box as a wolf and away you go.
Anyways, with the above done, you’d need to make a quest script. So You can have this in one giant class, but you need to make sure you use the playerprefs (See scripting reference OR Youtube!). So for my first quest, which this falls under, let’s say we make a playerpref
So we do PlayerPrefs.SetInt("Quest1",0);
This basically makes our playerprefs value for quest one, 0 being the default and therefore inactive.
So, if we then look at our npc script you can basically code up a GUI.Button saying “Yes”. What this will do is basically give us the option of letting the player accept the quest. If he or she accepts the quest you then want to declare the value set above as active, so therefore:
PlayerPrefs.SetInt("Quest1",1);
Will be between the button If statement. Now you might consider making the npc script for the start quest, middle quest (Ie when you go up to npc when quest is incomplete the text changes to “Have you killed those wolfs?”) and finally the end, where you declare the quest done and change the player prefs to :
PlayerPrefs.SetInt("Quest1",2);
Note: we set it 1 higher than the active value and not 0 as we don’t want the player to have the quest reset(unless you want that feature).
Now back to the part where the player accepts the quest, so in our example we want the player to kill say 8 wolfs, when he or she accepts in our code :
PlayerPrefs.SetInt("Quest1",1);
so then in our Enemy class OR What ever your are using which keeps track of the wolf health, you want to setup a singleton, All you need to do is within the wolf health script, ie where the health is = 0 (or the wolf dies).
you make an : if(PlayerPrefs.SetInt("Quest1",1)){Singletongoes inside here }
Once you’ve setup a singleton, you can then go back to the quest middle, as forexample if you setup a quest counter on the side, set the current wolfs killed count to rise. To make this rise, you basically make the singleton raise the current wolfs killed int by 1, per kill. Then after that it’s just a case of when current wolfs killed = max wolfs killed:
PlayerPrefs.SetInt("Quest1",2); And then the quest complete GUI become active.
I really hope this helps you, I tried to make that as easy to follow as possible. I did the playerprefs in c# so if you’re a java user you may need to change that. Now I was under the assumption you’d know what a singleton is, however if you don’t there are loads of tutorials regarding singletons on youtube so please check those out, also if your not good a doing class’s check out burgzergarcades tuts and learn about arrays.
Anyways i hope this helps you understand how to make a quest system ingame.
Regards,
Ice