37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
namespace Code.Gameplay.Door
|
|
{
|
|
public class Door : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform doorPolotno;
|
|
private Vector3 _doorInitialPosition;
|
|
private Quaternion _doorInitialRotation;
|
|
[SerializeField] private Transform hingeJointAnchor;
|
|
[SerializeField] private HingeJoint hingeJoint;
|
|
[SerializeField] private Rigidbody rigidbody;
|
|
|
|
public void TranslationMode(bool on)
|
|
{
|
|
if (on)
|
|
{
|
|
rigidbody.isKinematic = true;
|
|
return;
|
|
}
|
|
_doorInitialPosition = doorPolotno.position;
|
|
_doorInitialRotation = doorPolotno.rotation;
|
|
|
|
rigidbody.isKinematic = false;
|
|
hingeJoint.autoConfigureConnectedAnchor = false;
|
|
hingeJoint.connectedAnchor = hingeJointAnchor.position;
|
|
}
|
|
|
|
public void CloseTheDoor()
|
|
{
|
|
TranslationMode(true);
|
|
doorPolotno.DORotate(_doorInitialRotation.eulerAngles, 0.5f);
|
|
doorPolotno.DOMove(_doorInitialPosition, 0.5f);
|
|
}
|
|
}
|
|
} |