Здоровье чутка изменено
This commit is contained in:
1 parent
653342d080
commit
4ecafef8ee
6 files changed
+27
-50
No files matched your search
@@ -15,13 +15,11 @@ namespace Code.Example.Platformer.Entity
|
||||
[SerializeField] protected SpriteRenderer spriteRenderer;
|
||||
[SerializeField] private Vector2 groundPoint;
|
||||
|
||||
private EntityHealth _health;
|
||||
private PlatformerEntityData _data;
|
||||
|
||||
public void SetData(PlatformerEntityData data)
|
||||
{
|
||||
_data = data;
|
||||
_health = new(data.maxHealth);
|
||||
}
|
||||
|
||||
protected bool onGround;
|
||||
@@ -51,7 +49,5 @@ namespace Code.Example.Platformer.Entity
|
||||
}
|
||||
|
||||
protected abstract void Move();
|
||||
|
||||
public virtual void GetDamage(int damage) => _health.GiveDamage(damage);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity
|
||||
{
|
||||
public class EntityHealth
|
||||
public class EntityHealth : MonoBehaviour
|
||||
{
|
||||
private int _health, _maxHealth;
|
||||
private int _health;
|
||||
private int _maxHealth;
|
||||
public void SetMaxHealth(int maxHealth) => _maxHealth = maxHealth;
|
||||
public bool IsDead { get; private set; }
|
||||
|
||||
public EntityHealth(int initialHealth)
|
||||
{
|
||||
_health = initialHealth;
|
||||
}
|
||||
|
||||
public void GiveDamage(int damage)
|
||||
{
|
||||
_health -= damage;
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Code.Example.Platformer.Entity
|
||||
{
|
||||
public interface IPlatformerEnemyFactory
|
||||
{
|
||||
UniTaskVoid LoadEnemy(PlatformerEntityType enemyType);
|
||||
UniTaskVoid WarmEnemy(PlatformerEntityType enemyType);
|
||||
void ReleaseEnemy(PlatformerEntityType racerType);
|
||||
|
||||
UniTaskVoid SpawnEnemy(
|
||||
@@ -45,12 +45,11 @@ namespace Code.Example.Platformer.Entity
|
||||
await _enemyConfigsHandle.ToUniTask();
|
||||
|
||||
_enemyConfigs = _enemyConfigsHandle.Result.ToDictionary(x => x.EntityData.type);
|
||||
_enemyConfigs.Remove(PlatformerEntityType.Player);
|
||||
|
||||
_eventBus.RaiseEvent<IPlatformerEnemyFactoryInitializedHandle>(x => x.PlatformerEnemyFactoryInitialized());
|
||||
}
|
||||
|
||||
public async UniTaskVoid LoadEnemy(PlatformerEntityType enemyType)
|
||||
public async UniTaskVoid WarmEnemy(PlatformerEntityType enemyType)
|
||||
{
|
||||
if (enemyType == PlatformerEntityType.Player) return;
|
||||
|
||||
@@ -66,10 +65,14 @@ namespace Code.Example.Platformer.Entity
|
||||
Addressables.LoadAssetAsync<GameObject>(_enemyConfigs[enemyType].prefabReference));
|
||||
|
||||
await _enemyPrefabsHandle[enemyType].ToUniTask();
|
||||
var racer = _enemyPrefabsHandle[enemyType].Result.GetComponent<Entity>();
|
||||
racer.SetData(_enemyConfigs[enemyType].EntityData);
|
||||
|
||||
_eventBus.RaiseEvent<IPlatformerEnemyLoadedHandle>(x => x.PlatformerEnemyLoaded(enemyType, racer));
|
||||
|
||||
var entity = _enemyPrefabsHandle[enemyType].Result.GetComponent<Entity>();
|
||||
entity.SetData(_enemyConfigs[enemyType].EntityData);
|
||||
|
||||
var health = _enemyPrefabsHandle[enemyType].Result.GetComponent<EntityHealth>();
|
||||
health.SetMaxHealth(_enemyConfigs[enemyType].EntityData.maxHealth);
|
||||
|
||||
_eventBus.RaiseEvent<IPlatformerEnemyLoadedHandle>(x => x.PlatformerEnemyLoaded(enemyType, entity));
|
||||
}
|
||||
|
||||
public void ReleaseEnemy(PlatformerEntityType racerType)
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace Code.Example.Platformer.Entity
|
||||
|
||||
foreach (var damaged in damagedOnes)
|
||||
{
|
||||
damaged.gameObject.GetComponent<Entity>().GetDamage(1);
|
||||
damaged.gameObject.GetComponent<EntityHealth>().GiveDamage(1);
|
||||
_audioService.PlayOneShot(AudioNames.UISounds, 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user