LethalCompany/Lethal Company/ExportedProject/Assets/Scripts/Assembly-CSharp/PhysicsKnockbackOnHit.cs
2023-12-22 18:30:10 -05:00

20 lines
623 B
C#

using GameNetcodeStuff;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PhysicsKnockbackOnHit : MonoBehaviour, IHittable
{
public AudioClip playSFX;
public void Hit(int force, Vector3 hitDirection, PlayerControllerB playerWhoHit = null, bool playHitSFX = false)
{
if (!(base.gameObject.GetComponent<Rigidbody>() == null))
{
base.gameObject.GetComponent<Rigidbody>().AddForce(hitDirection * force * 10f, ForceMode.Impulse);
if (playSFX != null && (bool)base.gameObject.GetComponent<AudioSource>())
{
base.gameObject.GetComponent<AudioSource>().PlayOneShot(playSFX);
}
}
}
}