Door Interactions
This commit is contained in:
20
Assets/Project Files/Scripts/Shumpei/DoorController.cs
Normal file
20
Assets/Project Files/Scripts/Shumpei/DoorController.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
11
Assets/Project Files/Scripts/Shumpei/DoorController.cs.meta
Normal file
11
Assets/Project Files/Scripts/Shumpei/DoorController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f56717b6302ac07418400cc124cf091e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
55
Assets/Project Files/Scripts/Shumpei/PhysicsButton.cs
Normal file
55
Assets/Project Files/Scripts/Shumpei/PhysicsButton.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
11
Assets/Project Files/Scripts/Shumpei/PhysicsButton.cs.meta
Normal file
11
Assets/Project Files/Scripts/Shumpei/PhysicsButton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3309089836901644bcce7402b672a82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47a5e670191c5504b9c5b97a17d4678f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user