ublic class MobSpawner : MonoBehaviour
p
{
public GameObject Slime; // Full Code Credit : Ahanaf
public Transform spawnPoint;
public Button spawnButton;
public float spawnDelay = 0.5f;
rivate List<GameObject> activeSlimes = new List<GameObject>();
p
private bool isSpawning = false;
rivate int currentWave = 1;
p
public int slimeIncrement = 2;
oid Update()
v
{
CleanupSlimeList();
if ([Link] == 0 && !isSpawning && spawnButton != null && ![Link])
{
[Link] = true;
}
{
currentWave++;
StartCoroutine(SpawnSlimesWithDelay());
}
}
public void OnSpawnButtonPressed()
{
if (spawnButton != null)
[Link] = false;
StartCoroutine(SpawnSlimesWithDelay());
}
IEnumerator SpawnSlimesWithDelay()
{
isSpawning = true;
int slimeCountThisWave = baseSlimeCount + slimeIncrement * (currentWave - 1);
f or (int i = 0; i < slimeCountThisWave; i++)
{
Vector3 spawnPos = spawnPoint != null ? [Link] : [Link];
GameObject slime = Instantiate(Slime, spawnPos, [Link]);
[Link](slime);
yield return new WaitForSeconds(spawnDelay);
}
isSpawning = false;
}
oid CleanupSlimeList()
v
{
[Link](slime => slime == null);
}
}
ublic class MovementScript : MonoBehaviour
p
{
public GameObject Mob;
ublic Vector3 UpDirection = [Link];
p
public Vector3 DownDirection = [Link];
public Vector3 LeftDirection = [Link];
public Vector3 RightDirection = [Link];
public float moveSpeed = 5f;
private Vector3 moveDirection = [Link];
oid Update()
v
{
if (moveDirection != [Link])
{
[Link] += [Link] * moveSpeed * [Link];
}
}
rivate void OnTriggerEnter2D(Collider2D other)
p
{
if ([Link]("Upwards"))
{
moveDirection += UpDirection;
}
else if ([Link]("Downwards"))
{
moveDirection += DownDirection;
}
else if ([Link]("Leftwards"))
{
moveDirection += LeftDirection;
}
else if ([Link]("Rightwards"))
{
moveDirection += RightDirection;
}
if ([Link]("RemoveEnd"))
{
Destroy(Mob);
}
}
rivate void OnTriggerExit2D(Collider2D other)
p
{
if ([Link]("Upwards"))
{
moveDirection -= UpDirection;
}
else if ([Link]("Downwards"))
{
moveDirection -= DownDirection;
}
else if ([Link]("Leftwards"))
{
moveDirection -= LeftDirection;
}
else if ([Link]("Rightwards"))
{
moveDirection -= RightDirection;
}
}
}
public class EnemyHealth : MonoBehaviour
{
public float maxHealth = 50f;
private float currentHealth;
oid Start()
v
{
currentHealth = maxHealth;
}
ublic void TakeDamage(float amount)
p
{
currentHealth -= amount;
if (currentHealth <= 0)
{
Destroy(gameObject);
}
}
}
public class TowerStats : MonoBehaviour
{
ublic float damage = 10f;
p
public float range = 2f;
public float attackRate = 1f; // Time between attacks in seconds
private float attackTimer = 0f;
oid Update()
v
{
attackTimer -= [Link];
if (attackTimer <= 0f)
{
GameObject target = FindNearestEnemy();
if (target != null)
{
Attack(target);
attackTimer = attackRate;
}
}
}
ameObject FindNearestEnemy()
G
{
Collider2D[] hits = [Link]([Link], range);
float closestDistance = [Link];
GameObject closestEnemy = null;
f oreach (Collider2D hit in hits)
{
if ([Link]("Enemy"))
{
float dist = [Link]([Link], [Link]);
if (dist < closestDistance)
{
closestDistance = dist;
closestEnemy = [Link];
}
}
}
return closestEnemy;
}
oid Attack(GameObject enemy)
v
{
EnemyHealth eh = [Link]<EnemyHealth>();
if (eh != null)
{
[Link](damage);
}
}
oid OnDrawGizmosSelected()
v
{
[Link] = [Link];
[Link]([Link], range);
}
}
ublic class WarriorTowerPlacer : MonoBehaviour
p
{
public GameObject warriorTowerPrefab; // Assign in Inspector
public Vector2 placementPosition = new Vector2(0, 0); // Coordinate to place the tower
[ Header("Warrior Stats")]
public float damage = 10f;
public float range = 2f;
oid Update()
v
{
if ([Link](KeyCode.Alpha1))
{
PlaceWarriorTower();
}
}
oid PlaceWarriorTower()
v
{
if (warriorTowerPrefab != null)
{
GameObject tower = Instantiate(warriorTowerPrefab, placementPosition, [Link]);
// Try to assign damage and range if the tower has a TowerStats component
TowerStats stats = [Link]<TowerStats>();
if (stats != null)
{
[Link] = damage;
[Link] = range;
}
else
{
[Link]("The Warrior Tower prefab is missing a TowerStats component!");
}
}
else
{
[Link]("Warrior Tower Prefab is not assigned!");
}
}
}