- Home /
NPC Class looking for help
So, I'm trying to set up a basic NPC... all it has for stats is current and max health, but I'm not using the scene editor for this project, it's all in the scripting. So I'm curious as to the most efficient way to do this.
using UnityEngine;
using System.Collections;
public class BasicEnemy {
GameObject[] basicEnemy;
void Start() {
basicEnemy += GameObject.CreatePrimitive(PrimitiveType.Cube);
basicEnemy += GameObject.CreatePrimitive(PrimitiveType.Cube);
basicEnemy += GameObject.CreatePrimitive(PrimitiveType.Cube);
basicEnemy += GameObject.CreatePrimitive(PrimitiveType.Cube);
basicEnemy += GameObject.CreatePrimitive(PrimitiveType.Cube);
basicEnemy[0].tag = "Mob";
basicEnemy[1].tag = "Mob";
basicEnemy[2].tag = "Mob";
basicEnemy[3].tag = "Mob";
basicEnemy[4].tag = "Mob";
}
}
public enum BasicEnemyStats {
currentHealth,
maxHealth
}
my goal is to get a group of enemies that all have the currentHealth and maxHealth stats, while doing this I will use the array to combat NPC's of a certain type until there are none left. Thus winning the game.
Answer by coastwise · Jan 21, 2013 at 08:54 PM
I understand and appreciate that you want to create your mob through scripting, thats awesome! I would recommend however, first creating a single instance of your mob NPC in the editor and testing it out. Attach your custom Mob Monobehaviour script (which has currentHealth and maxHealth public members) to this object, its mesh (or cube), etc, etc. When it's all nice and working how you like, turn it into a prefab.
A prefab is like a cookie cutter for game objects. You make one, then you can reuse it to create as many copies (clones) as you like in a scene (through scripting).
So you would then make a MobSpawner script (inheriting from Monobehaviour as well) that would instantiate as many copies as are needed. You'd drop this spawner in your scene and let the havoc unfold.
I apologise if this answer is too high-level, please let me know if you could use further clarification.
Thanks for your reply, although I don't want to use the editor. I've done this before, and I know how to do it that way. I know what Instantiating is aswell, although none of my scripts inherit from $$anonymous$$onoBehavior besides for my Application$$anonymous$$anager script, which runs all of my other scripts through instances, I'm trying to do this without using the editor in any way shape or form. Considering I'm using C# Instantiating seems to not be working as it should, calling for different parameters than the scripting references are asking for. I've honestly yet to get it to work properly.
Thanks for your answer... Also, I don't know what I was thinking with the above script... O_O, looking at it again... I'm like "What... the hell."
Your answer
Follow this Question
Related Questions
Making changes to a terrian in game 1 Answer
C# Check If Scripted Gameobject goes Past Variable Gameobject 0 Answers
C# Make Child Not Animate Looped Animation 1 Answer
C# GameObjectList not Setting Parent 0 Answers
Multiple Cars not working 1 Answer