fix upgrades

This commit is contained in:
myondev 2026-03-03 09:16:19 -08:00
parent d8c49317a3
commit 5dcbd3c313
17 changed files with 477 additions and 83 deletions

View file

@ -12,6 +12,7 @@ public class Enemy : Entity
public EnemyAbility ability;
public float currentCooldown;
}
public static event Action OnDamaged;
[Header("Targetting")]
public Entity closestTarget;
public float engagementRange;
@ -112,6 +113,12 @@ public class Enemy : Entity
}
}
public override void TakeDamage(float damage)
{
base.TakeDamage(damage);
OnDamaged?.Invoke();
}
protected virtual void DropUpgrade(UpgradeDrop drop)
{
float random = Random.Range(0, 100);

View file

@ -29,10 +29,14 @@ public class EnemySpawner : MonoBehaviour
[SerializeField] private float currentSpawnTime;
[Header("Boss")]
public Enemy bossEnemy;
private Enemy bossEnemyInstance;
public Transform bossSpawnPoint;
[SerializeField] private GameObject bossUI;
[SerializeField] private Transform bossHealthBar;
[Header("Cache")]
[SerializeField] private Transform enemyFolder;
[SerializeField] private Marisa player;
private void Update()
{
if (canSpawn)
@ -46,16 +50,24 @@ public class EnemySpawner : MonoBehaviour
}
}
public void SpawnEnemy(Enemy enemy, Vector3 location)
public Enemy SpawnEnemy(Enemy enemy, Vector3 location)
{
Enemy newEnemy = Instantiate(enemy, location, Quaternion.identity);
newEnemy.transform.SetParent(enemyFolder);
newEnemy.closestTarget = player; //idk if there's actually gonna be any other target lol
return newEnemy;
}
public void StartBoss()
{
SpawnEnemy(bossEnemy, bossSpawnPoint.position);
bossEnemyInstance = SpawnEnemy(bossEnemy, bossSpawnPoint.position);
bossUI.SetActive(true);
canSpawn = false;
Enemy.OnDamaged += UpdateBossHealthBar; //this kinda sucks but it technically works??
}
private void UpdateBossHealthBar()
{
bossHealthBar.localScale = new Vector3(Math.Clamp(bossEnemyInstance.health / bossEnemyInstance.maxHealth, 0, bossEnemyInstance.maxHealth), 1, 1);
}
}

View file

@ -1,3 +1,4 @@
using System;
using UnityEngine;
public class Entity : MonoBehaviour
@ -11,6 +12,7 @@ public class Entity : MonoBehaviour
[Header("Stats")]
public float health;
public float maxHealth;
[Header("Movement")]
[SerializeField] private bool isFacingRight;
[SerializeField] protected Rigidbody2D rb;
@ -37,7 +39,7 @@ public class Entity : MonoBehaviour
rb.linearVelocity = moveDirection * speed;
}
}
public void TakeDamage(float damage)
public virtual void TakeDamage(float damage)
{
health -= damage;
if (health < 0)

View file

@ -9,6 +9,8 @@ public class Marisa : Entity
public Vector2 mouseWorldPos;
public Transform firingPointBase;
public Transform firingPoint;
[Header("UI")]
[SerializeField] private Transform hpBarUI;
private void Update()
{
mouseWorldPos = cam.ScreenToWorldPoint(Input.mousePosition);
@ -20,4 +22,15 @@ public class Marisa : Entity
moveDirection = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
base.FixedUpdate();
}
public override void TakeDamage(float damage)
{
base.TakeDamage(damage);
UpdateHealthUI();
}
private void UpdateHealthUI()
{
hpBarUI.localScale = new Vector3(Math.Clamp(health/maxHealth,0,maxHealth), 1,1);
}
}