2025-03-17 20:17:49 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class SpawnScanner : MonoBehaviour
|
|
|
|
|
{
|
2025-03-19 14:35:19 +01:00
|
|
|
|
// Prefabs
|
2025-03-17 20:17:49 +01:00
|
|
|
|
[SerializeField] private GameObject platform;
|
2025-03-19 14:35:19 +01:00
|
|
|
|
[SerializeField] private GameObject enemy;
|
|
|
|
|
public bool isAllowedToSpawn = true;
|
|
|
|
|
|
|
|
|
|
// Platform Spawner
|
2025-03-17 20:17:49 +01:00
|
|
|
|
private void OnTriggerExit2D(Collider2D collision)
|
|
|
|
|
{
|
2025-03-19 14:35:19 +01:00
|
|
|
|
if (collision.gameObject.tag.Equals("Ground") && isAllowedToSpawn)
|
|
|
|
|
{
|
|
|
|
|
Spawn();
|
|
|
|
|
}
|
2025-03-17 20:17:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Spawn()
|
|
|
|
|
{
|
2025-03-18 21:14:56 +01:00
|
|
|
|
float height = Random.Range(-2f, -1f);
|
|
|
|
|
Vector3 positionPLat = new Vector3(12f, height, 0f);
|
2025-03-19 14:35:19 +01:00
|
|
|
|
GameObject newPlatform = Instantiate(platform, positionPLat, Quaternion.identity);
|
|
|
|
|
int w<EFBFBD>rfel = Random.Range(1, 4);
|
|
|
|
|
if (w<EFBFBD>rfel == 3)
|
|
|
|
|
{
|
|
|
|
|
SpawnEnemy(newPlatform);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Enemy spawns on platform
|
|
|
|
|
private void SpawnEnemy(GameObject platformAdress)
|
|
|
|
|
{
|
|
|
|
|
Vector3 enemyPosition = platformAdress.transform.position + new Vector3(0f, 1f, 0f);
|
|
|
|
|
GameObject newEnemy = Instantiate(enemy, enemyPosition, Quaternion.identity);
|
|
|
|
|
|
|
|
|
|
// Enemy moves along the platform
|
|
|
|
|
newEnemy.transform.parent = platformAdress.transform;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void stopSpawn()
|
|
|
|
|
{
|
|
|
|
|
isAllowedToSpawn = false;
|
2025-03-17 20:17:49 +01:00
|
|
|
|
}
|
|
|
|
|
}
|