1
This commit is contained in:
@@ -7,48 +7,32 @@ using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.Sensors;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations;
|
||||
|
||||
namespace BITFALL.Props
|
||||
{
|
||||
public class Prop_BouncingBetty : MonoBehaviour
|
||||
{
|
||||
[SerializeReference,SubclassSelector] private ISensor rangeSensor;
|
||||
[SerializeReference, SubclassSelector] private IReference[] vfxTags;
|
||||
[SerializeField] private AnimationCurve damageCurve;
|
||||
[SerializeField] private LayerMask physicsLayer;
|
||||
[SerializeField] private float explosionRadius;
|
||||
[SerializeField] private float jumpForce;
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
private bool isTriggered;
|
||||
public async void OnDetected(Collider _collider)
|
||||
{
|
||||
if (isTriggered) return;
|
||||
rigidbody.isKinematic = false;
|
||||
rigidbody.useGravity = true;
|
||||
if(TryGetComponent<ParentConstraint>(out var parentConstraint))
|
||||
Destroy(parentConstraint);
|
||||
isTriggered = true;
|
||||
var damaged = new List<ulong>() ;
|
||||
rigidbody.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000,destroyCancellationToken);
|
||||
GetComponentInChildren<Prop_Explosive>().Explosion(gameObject);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DI.Get<VFXService>().Spawn(new Location(transform), vfxTags.Select(x=>x.Value).ToArray());
|
||||
foreach (var x in rangeSensor.Get())
|
||||
{
|
||||
if (!x.TryGetComponent<Entity>(out var entity)) continue;
|
||||
if(damaged.Contains(entity.Id))continue;
|
||||
entity.Invoke<DamageMessage>(new DamageMessage()
|
||||
{
|
||||
Target = entity,
|
||||
Damage = (int)damageCurve.Evaluate(Vector3.Distance(transform.position, entity.transform.position))
|
||||
});
|
||||
damaged.Add(entity.Id);
|
||||
}
|
||||
PhysicsHelper.Explosion(transform.position,explosionRadius,physicsLayer,1024*8);
|
||||
damaged.Clear();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user