using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Target : MonoBehaviour
{
public float health = 50f;
private EnemySpawn enemySpawnScript;
public GameObject enemySpawner;
public int enemiesKilled;
// Start is called before the first frame update
void Start()
{
enemySpawner = GameObject.Find("EnemySpawner2");
enemySpawnScript = enemySpawner.GetComponent<EnemySpawn>();
}
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0.0f)
{
enemySpawnScript.enemiesSpawned -= 2;
Destroy(gameObject);
}
}
// Update is called once per frame
}
The variable in question is enemySpawnScript.enemiesSpawned
The script this comes from is
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawn : MonoBehaviour
{
public GameObject theEnemy;
public GameObject theTank;
public GameObject theMiniBoss;
private int xPos;
private int zPos;
public bool gameStart = false;
double diffCount;
int sc;
bool loopRun = true;
public bool levelTut = false;
float stimer;
public int enemiesSpawned = 0;
// Start is called before the first frame update
public void Start()
{
}
// Update is called once per frame
void Update()
{
print("EnemiesSpawned" + enemiesSpawned);
if (enemiesSpawned == 0 && loopRun == true)
{
SpawnEnemies();
loopRun = false;
}
}
void GenerateEnemy()
{
xPos = UnityEngine.Random.Range(-5, 5);
zPos = UnityEngine.Random.Range(-5, 5);
Instantiate(theEnemy, new Vector3(xPos, 2, zPos), Quaternion.identity);
}
void GenerateTank()
{
xPos = UnityEngine.Random.Range(-5, 5);
zPos = UnityEngine.Random.Range(-5, 5);
Instantiate(theTank, new Vector3(xPos, 2, zPos), Quaternion.identity);
}
void GenerateMiniBoss()
{
xPos = UnityEngine.Random.Range(-5, 5);
zPos = UnityEngine.Random.Range(-5, 5);
Instantiate(theMiniBoss, new Vector3(xPos, 2, zPos), Quaternion.identity);
}
void SpawnEnemies()
{
if (levelTut != true)
{
if (gameStart == true)
{
for (sc = 0, stimer = 1; diffCount <= 1 && sc <= 2; sc++, stimer++)
{
Invoke("GenerateEnemy", 1.5f * stimer);
enemiesSpawned+=2;
}
for (sc = 0, stimer = 1; diffCount <= 3 && sc <= 5 && diffCount > 1; sc++, stimer++)
{
Invoke("GenerateEnemy", 1.2f * stimer);
enemiesSpawned++;
}
for (sc = 0, stimer = 1; diffCount <= 6 && sc <= 5 && diffCount > 3; sc++, stimer++)
{
if (sc < 3)
{
Invoke("GenerateEnemy", 0.9f * stimer);
enemiesSpawned++;
}
else
{
Invoke("GenerateTank", 1.5f * stimer);
enemiesSpawned++;
}
}
for (sc = 0, stimer = 1; diffCount <= 9 && sc <= 7 && diffCount > 6; sc++, stimer++)
{
if (sc < 3)
{
Invoke("GenerateEnemy", 0.9f * stimer);
enemiesSpawned++;
}
else if (sc < 6)
{
Invoke("GenerateTank", 0.9f * stimer);
enemiesSpawned++;
}
else
{
Invoke("GenerateMiniBoss", 0.9f * stimer);
enemiesSpawned++;
}
}
loopRun = true;
diffCount++;
if (diffCount == 10)
gameStart = false;
}
}
else
{
for (sc = 0, stimer = 1; diffCount <= 9 && sc <= 7; sc++, stimer++) //&& diffCount > 3
{
if (sc < 3)
{
Invoke("GenerateEnemy", 0.9f * stimer);
enemiesSpawned++;
}
else if (sc < 6)
{
Invoke("GenerateTank", 0.9f * stimer);
enemiesSpawned++;
}
else
{
Invoke("GenerateMiniBoss", 0.9f * stimer);
enemiesSpawned++;
}
}
}
}
}