LethalCompany/Lethal Company/ExportedProject/Assets/Scripts/Assembly-CSharp/PhysicsKnockbackOnHit.cs

23 lines
647 B
C#
Raw Normal View History

2023-12-22 22:51:17 +00:00
using GameNetcodeStuff;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PhysicsKnockbackOnHit : MonoBehaviour, IHittable
{
public AudioClip playSFX;
2023-12-23 02:13:19 +00:00
public bool Hit(int force, Vector3 hitDirection, PlayerControllerB playerWhoHit = null, bool playHitSFX = false)
2023-12-22 22:51:17 +00:00
{
2023-12-23 02:13:19 +00:00
if (base.gameObject.GetComponent<Rigidbody>() == null)
2023-12-22 22:51:17 +00:00
{
2023-12-23 02:13:19 +00:00
return false;
2023-12-22 22:51:17 +00:00
}
2023-12-23 02:13:19 +00:00
base.gameObject.GetComponent<Rigidbody>().AddForce(hitDirection * force * 10f, ForceMode.Impulse);
if (playSFX != null && (bool)base.gameObject.GetComponent<AudioSource>())
{
base.gameObject.GetComponent<AudioSource>().PlayOneShot(playSFX);
}
return true;
2023-12-22 22:51:17 +00:00
}
}