enemy spawner
i have this bug when i kill an enemy every enemy gets killed with him or when the spawner spawn a second one while your hitting the first it gets double health idk how to fix it and if someone can help i will very thankfull this is the spawner script using System.Collections; using System.Collections.Generic; using UnityEngine;
public class EnemySpawnerScript : MonoBehaviour {
public GameObject enemy;
float randX;
Vector2 whereToSpawn;
public float spawnRate = 2f;
float nextSpawn = 0.0f;
// Update is called once per frame
void Update()
{
if (Time.time > nextSpawn)
{
nextSpawn = Time.time + spawnRate;
randX = Random.Range(-20f, 20f);
whereToSpawn = new Vector2(randX, transform.position.y);
Instantiate(enemy, whereToSpawn, Quaternion.identity);
}
}
}
and this is the enemy killing script
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class KillingDrop : MonoBehaviour {
public GameObject lootDrop;
public static float healthAmount;
void Start()
{
healthAmount = 3;
}
void Update ()
{
if (healthAmount <= 1)
{
Destroy(gameObject);
Instantiate(lootDrop, transform.position, Quaternion.identity);
}
}
void OnCollisionEnter2D (Collision2D col)
{
if (col.gameObject.tag.Equals("Bullet"))
{
Destroy(col.gameObject);
healthAmount -= 1;
}
}
}
Your answer
Follow this Question
Related Questions
I can’t really get the spawner working. 0 Answers
I can't get my spawner to work! pls help fast. 0 Answers
Death restart 3 Answers
Animation Help? (2D) 1 Answer
How to make a death pickup 2d 0 Answers