1
This commit is contained in:
40
Assets/Artists/Scripts/Props/Prop_Fixed.cs
Normal file
40
Assets/Artists/Scripts/Props/Prop_Fixed.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class Prop_Fixed : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
[SerializeField] private LayerMask allowLayer;
|
||||
|
||||
private Collider _collider;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if(rigidbody.isKinematic)Destroy(this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!rigidbody.IsSleeping() || !_collider) return;
|
||||
if (_collider.gameObject.isStatic)
|
||||
{
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
enabled = false;
|
||||
transform.SetParentConstraint(_collider.transform);
|
||||
rigidbody.isKinematic = true;
|
||||
}
|
||||
private void OnCollisionStay(Collision other)
|
||||
{
|
||||
if (allowLayer.value is not 0 && allowLayer.Includes(other.gameObject.layer) is false) return;
|
||||
_collider = other.collider;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user