Hey folks!
I’m still somewhat new to unity, and starting to work on a little game (mostly to practise), and i’m bit stuck at one point, and not sure what would be the best way to proceed.
So, for starters, i have IEnemyBase interface:
using UnityEngine;
using System.Collections;
public interface IEnemyBase
{
string enemyName {get; set;} //name of the enemy
float health {get; set;} //How much health the enemy has
float shield {get; set;} //How much shield enemy has
float enemySpeed{get;set;} //how fast does enemy move
GameObject enemyPrefab{get;set;} //prefab that enemy will use (model, particles, collision....
void move();
}
And class that implements this interface.
public class EnemyBase : IEnemyBase
{
private string _enemyName = "DefaultProjectileName";
private float _health = 100.0f;
private float _shield = 100.0f;
private float _enemySpeed = 1.0f;
private GameObject _enemyPrefab = null;
public void move ()
{
}
public string enemyName
{
get
{
return _enemyName;
}
set
{
_enemyName = value;
}
}
public float health
{
get
{
return _health;
}
set
{
_health = value;
}
}
public float shield
{
get
{
return _shield;
}
set
{
_shield = value;
}
}
public float enemySpeed
{
get
{
return _enemySpeed;
}
set
{
_enemySpeed = value;
}
}
public GameObject enemyPrefab
{
get
{
return _enemyPrefab;
}
set
{
_enemyPrefab = value;
}
}
}
Now, lets say i want to create enemy “Generic_Enemy_1” based on this class. Lets say i have “Generic_Enemy_1_prefab”, meaning, model, particle system, collision mesh, etc.
I assume i should create new script, “generic_enemy_1” class, and assign this class to this prefab, and it extends MonoBehaviour class.
But this is where i’m getting a little confused.
So, idea was to have EnemySpawner in the scene, and it would, say, generate 20 enemies, on random positions, and each enemy would have it’s own class instance (object) of the EnemyBase class. This way, i could keep track health status and such things for each of the enemy, but i’m not really sure how to approach this.
Also, since gameObject(enemy prefab) must have a script with class that extends monobehaviour, i’m not really sure how should i connect enemy prefab (+ assinged Script) with the enemyBase class (or it’s object). And above all, how to then keep track on health status of each enemy within the main script of the game that will handle these things?
Anyhow, i hope someone can give me some idea how to approach this particular problem.
Tnx!