From 1ef7a241426e09d3714781c4c2d056f3ebb322ff Mon Sep 17 00:00:00 2001 From: ALoTron <34157676+ALoTron@users.noreply.github.com> Date: Sat, 21 Apr 2018 16:12:04 +0200 Subject: [PATCH] Added entity-spawn and kill --- Assets/Scripts/Entities/Entity.cs | 32 +++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/Entities/Entity.cs b/Assets/Scripts/Entities/Entity.cs index af321fc..7230300 100644 --- a/Assets/Scripts/Entities/Entity.cs +++ b/Assets/Scripts/Entities/Entity.cs @@ -2,15 +2,31 @@ using System.Collections.Generic; using UnityEngine; -public class Entity : MonoBehaviour { +public class Entity { + EntityObjective referringObjective; + GameObject entityPrefab; + GameObject instance; - // Use this for initialization - void Start () { - + // Constructor + public Entity(EntityObjective referringObjective, GameObject entityPrefab) + { + this.referringObjective = referringObjective; + this.entityPrefab = entityPrefab; } - - // Update is called once per frame - void Update () { - + + // spawns the entity + public void Spawn(Transform spawnPoint) + { + instance = GameObject.Instantiate (entityPrefab); + instance.transform = spawnPoint; + } + + // kills the entity + public void Kill() + { + GameObject.Destroy (instance); + referringObjective.Remove (this); + + instance = null; } }