1
This commit is contained in:
43
Assets/Artists/Scripts/Props/Prop_Grenade.cs
Normal file
43
Assets/Artists/Scripts/Props/Prop_Grenade.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
|
||||
public class Prop_Grenade : MonoBehaviour
|
||||
{
|
||||
[SerializeReference, SubclassSelector] private ISensor rangeSensor;
|
||||
[SerializeReference, SubclassSelector] private IReference[] vfxTags;
|
||||
[SerializeField] private LayerMask physicsLayer;
|
||||
[SerializeField] private float explosionRadius;
|
||||
[SerializeField] private float fuse;
|
||||
[SerializeField] private AnimationCurve damageCurve;
|
||||
|
||||
private async void Start()
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(fuse), 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) is false)continue;
|
||||
entity.Invoke<DamageMessage>(new DamageMessage()
|
||||
{
|
||||
Target = entity,
|
||||
Damage = (int)damageCurve.Evaluate(Vector3.Distance(transform.position, entity.transform.position))
|
||||
});
|
||||
}
|
||||
PhysicsHelper.Explosion(transform.position,explosionRadius,physicsLayer,1024*8);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user