1
This commit is contained in:
55
Assets/Artists/Scripts/Props/Prop_BouncingBetty.cs
Normal file
55
Assets/Artists/Scripts/Props/Prop_BouncingBetty.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.Sensors;
|
||||
using UnityEngine;
|
||||
|
||||
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;
|
||||
isTriggered = true;
|
||||
var damaged = new List<ulong>() ;
|
||||
rigidbody.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000,destroyCancellationToken);
|
||||
}
|
||||
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