BITKit/Src/Unity/Scripts/Physics/PhysicsHelper.cs

31 lines
1.0 KiB
C#
Raw Normal View History

2023-10-24 23:38:22 +08:00
using System;
2023-06-05 19:57:17 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cysharp.Threading.Tasks;
namespace BITKit
{
public static class PhysicsHelper
{
2023-09-01 14:35:05 +08:00
public static async UniTask AddForceAtPositionAsync(this Rigidbody rigidbody, Vector3 force, Vector3 position,ForceMode forceMode=ForceMode.Force)
2023-06-05 19:57:17 +08:00
{
await UniTask.DelayFrame(8);
2023-10-24 23:38:22 +08:00
try
{
rigidbody.AddForceAtPosition(force, position,forceMode);
}
catch(MissingReferenceException){}
}
public static async void Explosion(Vector3 position,float radius,LayerMask layerMask,float force)
{
await UniTask.DelayFrame(8);
foreach (var x in UnityEngine.Physics.OverlapSphere(position,radius,layerMask))
{
if(x.attachedRigidbody is null)continue;
x.attachedRigidbody.AddExplosionForce(force,position,radius);
//Debug.Log(x);
}
2023-06-05 19:57:17 +08:00
}
}
}