53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
using System;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
namespace Code.Gameplay.Door
|
|
{
|
|
public class DoorDebug : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform doorSelf;
|
|
[SerializeField] private Transform doorPolotno;
|
|
private Vector3 _doorInitialPosition;
|
|
private Quaternion _doorInitialRotation;
|
|
[SerializeField] private Transform hingeJointAnchor;
|
|
[SerializeField] private HingeJoint hingeJoint;
|
|
[SerializeField] private Rigidbody rigidbody;
|
|
[SerializeField] private bool debug;
|
|
[SerializeField] private bool closed;
|
|
|
|
private void Start()
|
|
{
|
|
_doorInitialPosition = doorPolotno.position;
|
|
_doorInitialRotation = doorPolotno.rotation;
|
|
}
|
|
private void Update()
|
|
{
|
|
if(debug && !closed)
|
|
{
|
|
CloseTheDoor();
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |