Door Interactions

This commit is contained in:
2022-03-28 16:48:27 +03:00
parent c10f3421f5
commit fb14e165d4
29 changed files with 5770 additions and 3447 deletions

View File

@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorController : MonoBehaviour
{
[SerializeField] private Animator myDoor = null;
// Start is called before the first frame update
public void DoorOpen()
{
myDoor.Play("DoorOpen", 0, 0.0f);
}
public void DoorClose()
{
myDoor.Play("DoorClose", 0, 0.0f);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f56717b6302ac07418400cc124cf091e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class PhysicsButton : MonoBehaviour
{
[SerializeField] private float threshold = 0.1f;
[SerializeField] private float deadzone = 0.025f;
private bool _isPressed;
private Vector3 _startPos;
private ConfigurableJoint _joint;
public UnityEvent onPressed, onReleased;
// Start is called before the first frame update
void Start()
{
_startPos = transform.localPosition;
_joint = GetComponent<ConfigurableJoint>();
}
// Update is called once per frame
void Update()
{
if (!_isPressed && GetValue() + threshold >= 1)
Pressed();
if (_isPressed && GetValue() - threshold <= 0)
Released();
}
private float GetValue()
{
var value = Vector3.Distance(_startPos, transform.localPosition) / _joint.linearLimit.limit;
if (Mathf.Abs(value) < deadzone)
value = 0;
return Mathf.Clamp(value, -1f, 1f);
}
private void Pressed()
{
_isPressed = true;
onPressed.Invoke();
Debug.Log("Pressed");
}
private void Released()
{
_isPressed = false;
onReleased.Invoke();
Debug.Log("Released");
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f3309089836901644bcce7402b672a82
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TriggerDoorController : MonoBehaviour
{
[SerializeField] private Animator myDoor = null;
[SerializeField] private bool openTrigger = false;
[SerializeField] private bool closeTrigger = false;
[SerializeField] private string doorOpen = "DoorOpen";
[SerializeField] private string doorClose = "DoorClose";
// Start is called before the first frame update
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Debug.Log("col");
if (openTrigger)
{
Debug.Log("open");
myDoor.Play(doorOpen, 0, 0.0f);
gameObject.SetActive(false);
}
else if (closeTrigger)
{
myDoor.Play(doorClose, 0, 0.0f);
gameObject.SetActive(false);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 47a5e670191c5504b9c5b97a17d4678f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: