This commit is contained in:
JA
2026-06-27 03:36:18 +08:00
parent 2ab982a4e0
commit aec4e97d27
1151 changed files with 34150 additions and 102339 deletions

View File

@@ -0,0 +1,52 @@
using UnityEngine;
namespace IndianOceanAssets.Engine2_5D
{
// Controls enemy behavior: follows player and handles collision.
public class EnemyAI : MonoBehaviour
{
private Transform target; // Reference to the player
[SerializeField] private float speed; // Movement speed
[SerializeField] private int damageAmount; // Damage dealt to player
[SerializeField] private SpriteRenderer spriteRenderer; // For flipping sprite
// Called on start
public void Start()
{
Invoke("AssignPlayer", 1f); // Delay to ensure player exists
}
// Finds and assigns the player as target
public void AssignPlayer()
{
target = GameObject.FindGameObjectWithTag("Player").transform;
}
// Called every frame
public void Update()
{
if (target)
{
// Flip sprite based on direction to player
if (target.position.x > transform.position.x)
spriteRenderer.flipX = false;
else
spriteRenderer.flipX = true;
// Move towards player
transform.position = Vector3.MoveTowards(transform.position, target.position, Time.deltaTime * speed);
}
}
// Handles collision with player
void OnCollisionEnter(Collision collision)
{
if (collision.collider.CompareTag("Player"))
{
// Damage player and kill self
collision.collider.GetComponent<HealthSystem>().Damage(damageAmount);
GetComponent<HealthSystem>().Die();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 04126beb49efb8c49a7ecc822750a0c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,46 @@
using UnityEngine;
namespace IndianOceanAssets.Engine2_5D
{
// Spawns enemies at random positions and intervals
public class EnemySpawner : MonoBehaviour
{
[SerializeField]
private GameObject enemyEntity; // Enemy prefab
[SerializeField]
private Transform[] spawnPosition; // Possible spawn points
[SerializeField]
private float spawnTime = 4f; // Time between spawns
// Starts repeated spawning
private void Start()
{
InvokeRepeating("SpawnEnemies", 0f, spawnTime);
}
// Spawns a random number of enemies at random positions
public void SpawnEnemies()
{
int enemyNo = Random.Range(1, 4);
for (int i = 0; i < enemyNo; i++)
{
int randomSpawnPosition = Random.Range(0, spawnPosition.Length);
if (spawnPosition[randomSpawnPosition])
{
// Randomize spawn position slightly
Vector3 randomUnitCircle = new Vector3(Random.Range(-1f, 1f), .5f, Random.Range(-1f, 1f));
Instantiate(enemyEntity, spawnPosition[randomSpawnPosition].position + randomUnitCircle, Quaternion.identity);
}
}
// Decrease spawn time to increase difficulty, but not below 2 seconds
spawnTime -= .5f;
if (spawnTime <= 2f)
spawnTime = 2f;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c755496b98cf3a743b854c203125bdff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: