SanAndreasUnity/Assets/Scripts/Behaviours/Ped/DeadBody.cs

51 lines
1.5 KiB
C#
Raw Normal View History

2021-01-05 02:09:45 +00:00
using System.Collections.Generic;
2021-01-05 17:21:57 +00:00
using SanAndreasUnity.Utilities;
2021-01-05 02:09:45 +00:00
using UnityEngine;
namespace SanAndreasUnity.Behaviours.Peds
{
public class DeadBody : MonoBehaviour
{
private static List<DeadBody> _deadBodies = new List<DeadBody>();
public static IEnumerable<DeadBody> DeadBodies => _deadBodies;
public static int NumDeadBodies => _deadBodies.Count;
2021-01-05 17:21:57 +00:00
public PushableByDamage PushableByDamage { get; private set; }
private void Awake()
{
this.PushableByDamage = this.GetComponentOrThrow<PushableByDamage>();
this.PushableByDamage.forceMultiplier = PedManager.Instance.ragdollDamageForceWhenDetached;
}
2021-01-05 02:09:45 +00:00
private void OnEnable()
{
_deadBodies.Add(this);
}
private void OnDisable()
{
_deadBodies.Remove(this);
}
public static DeadBody Create(Transform ragdollTransform, Ped ped)
{
NetStatus.ThrowIfNotOnServer();
GameObject ragdollGameObject = Object.Instantiate(PedManager.Instance.ragdollPrefab);
DeadBody deadBody = ragdollGameObject.GetComponentOrThrow<DeadBody>();
Object.Destroy(ragdollGameObject, PedManager.Instance.ragdollLifetime * Random.Range(0.85f, 1.15f));
ragdollGameObject.name = "dead body " + ped.name;
ragdollTransform.SetParent(ragdollGameObject.transform);
NetManager.Spawn(ragdollGameObject);
return deadBody;
}
2021-01-05 02:09:45 +00:00
}
}