Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

[C#] Respawning system Enemies

$
0
0
I am making a game where once you kill an enemy, two more respawn and you score is based off of that. So far it was working for the first 2. I killed the first enemy, so it spawned two more but once i killed those, the 4 enemies that respawned were frozen in place but still had all the scripts on it, Idk if its a problem with my code so here it is: using UnityEngine; using System.Collections; public class EnemyHealth : MonoBehaviour { public int maxHealth; public int curHealth; protected Animation dmg; public Rigidbody2D enemyPrefab; void Start() { dmg = GetComponent(); curHealth = maxHealth; } void Update() { if (curHealth < 1) { Death(); } } void OnTriggerEnter2D(Collider2D col) { if (col.tag == "Bullet") { curHealth -= 1; Destroy(col.gameObject); dmg.Play("Damage"); } } void Death() { Destroy(gameObject); Rigidbody2D aPrefab = Instantiate(enemyPrefab, new Vector3(0, 0, 0), transform.rotation) as Rigidbody2D; Rigidbody2D bPrefab = Instantiate(enemyPrefab, new Vector3(0, 0, 0), transform.rotation) as Rigidbody2D; } } Thanks

Viewing all articles
Browse latest Browse all 1488

Trending Articles