- Home /
How should I create a NPC System?
This is my first project that I'm not going to use the editor in, so I won't be attatching a script to every single NPC that I've thrown in using the editor, instead I'm going to be using Handlers(Managers) I've gotten A lot of it down, to targetting, attacking, GUI, movement, Stats, Health, Mana, Skills, Interfaces, Sounds... but I'm having trouble with NPCs
What's the best way to go about doing this, considering I'm not using the editor at all, strictly code. I'm not asking for a hand-out, just an explanation on how to go about this efficiently, I have a current system but it only works for one npc, then all of them are dead because I don't have them stored separately.
How should I do this, GameObject array..... Scratches head Halp.
When you instantiate the NPC Gameobject you could just attach a component to it with .AddComponent. Then you are basically just scripting your drag'n drop in the editor.
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.AddComponent.html
I'm using instances, not components. Thanks, though.
Just wondering why? Do you you have some specific reason not to use $$anonymous$$onoBehaviours
Answer by hrlarsen · Jan 21, 2013 at 11:28 PM
Store them in a List and give them each a individual ID, something like this: private static int _ID = 0; public int ID;
somewhere in the NPC constructor (if you are not using Monobehaviour)
ID = _ID; _ID++;
and in you manager it would go something like:
List npcList = new List(); npcList.Add(this.NPC);
remember to use in your manager class using.System.Collections.Generic;
and then when it dies it would go something like:
for(int i = 0; i < npcList.Count; i++){ if(i == npcList[i].ID) npcList.Remove[i]; }
I understand this part, although my problem is wil adding attributes to the NPC after it was created.
$$anonymous$$y guess is that since you saying you are using instances, it would be instances of a NPC class. In which all the relevant attributes would be
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
I need help with an array 1 Answer
Unity is acting REALLY weird 0 Answers
Adding a SDK to my game 0 Answers