1
This commit is contained in:
31
Assets/Artists/Scripts/Feel/EntityHealthBlender.cs
Normal file
31
Assets/Artists/Scripts/Feel/EntityHealthBlender.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Feel
|
||||
{
|
||||
public sealed class EntityHealthBlender : EntityBehavior
|
||||
{
|
||||
[SerializeField] private Renderer[] _renderers;
|
||||
[Inject] private IHealth _health;
|
||||
private static readonly int Blend = Shader.PropertyToID("_Blend");
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
_health.OnSetHealthPoint += OnSetHealthPoint;
|
||||
}
|
||||
|
||||
private void OnSetHealthPoint(int obj)
|
||||
{
|
||||
var blend =1- Mathf.Clamp01(obj / (float)_health.MaxHealthPoint);
|
||||
foreach (var x in _renderers)
|
||||
{
|
||||
x.material.SetFloat(Blend, blend);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user