Program Code
Program Code
p
{
public GameObject Slime; // Full Code Credit : Ahanaf
public Transform spawnPoint;
public Button spawnButton;
oid Update()
v
{
CleanupSlimeList();
StartCoroutine(SpawnSlimesWithDelay());
}
IEnumerator SpawnSlimesWithDelay()
{
isSpawning = true;
int slimeCountThisWave = baseSlimeCount + slimeIncrement * (currentWave - 1);
isSpawning = false;
}
oid CleanupSlimeList()
v
{
activeSlimes.RemoveAll(slime => slime == null);
}
}
ublic class MovementScript : MonoBehaviour
p
{
public GameObject Mob;
oid Update()
v
{
if (moveDirection != Vector3.zero)
{
Mob.transform.position += moveDirection.normalized * moveSpeed * Time.deltaTime;
}
}
oid Start()
v
{
currentHealth = maxHealth;
}
oid Update()
v
{
attackTimer -= Time.deltaTime;
ameObject FindNearestEnemy()
G
{
Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, range);
float closestDistance = float.MaxValue;
GameObject closestEnemy = null;
return closestEnemy;
}
oid OnDrawGizmosSelected()
v
{
Gizmos.color = Color.blue;
Gizmos.DrawWireSphere(transform.position, 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 (Input.GetKeyDown(KeyCode.Alpha1))
{
PlaceWarriorTower();
}
}
oid PlaceWarriorTower()
v
{
if (warriorTowerPrefab != null)
{
GameObject tower = Instantiate(warriorTowerPrefab, placementPosition, Quaternion.identity);
// Try to assign damage and range if the tower has a TowerStats component
TowerStats stats = tower.GetComponent<TowerStats>();
if (stats != null)
{
stats.damage = damage;
stats.range = range;
}
else
{
Debug.LogWarning("The Warrior Tower prefab is missing a TowerStats component!");
}
}
else
{
Debug.LogWarning("Warrior Tower Prefab is not assigned!");
}
}
}