Throwing Knife Added
This commit is contained in:
52
Assets/Artists/Scripts/Props/Prop_ReplaceOnSleep.cs
Normal file
52
Assets/Artists/Scripts/Props/Prop_ReplaceOnSleep.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations;
|
||||
|
||||
namespace BITFALL.Props
|
||||
{
|
||||
public class Prop_ReplaceOnSleep : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform prefab;
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
private readonly IntervalUpdate _interval = new(0.16f);
|
||||
private Collider _collider;
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (rigidbody.IsSleeping() && _interval.AllowUpdate)
|
||||
{
|
||||
ReplaceImmediate(_collider.transform);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReplaceImmediate(Transform root=null)
|
||||
{
|
||||
var _transform = transform;
|
||||
var instance = Instantiate(prefab);
|
||||
instance.SetPositionAndRotation(_transform.position, _transform.rotation);
|
||||
|
||||
if (root is not null)
|
||||
{
|
||||
instance.SetParentConstraint(root);
|
||||
if (instance.TryGetComponent<Rigidbody>(out var _rigidbody))
|
||||
{
|
||||
//_rigidbody.isKinematic = true;
|
||||
_rigidbody.isKinematic = true;
|
||||
}
|
||||
}
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
_collider = other.collider;
|
||||
}
|
||||
|
||||
private void OnCollisionStay(Collision other)
|
||||
{
|
||||
_collider = other.collider;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user