Added extra sliders for audio (not audio logic not yet implemented) and got elevator outer buttons firing.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ElevatorCaller : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
print(other);
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb10405b50598284a8ff23d1edde1407
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/_PROJECT/Components/Elevator/Scripts/Push Button.cs
Normal file
25
Assets/_PROJECT/Components/Elevator/Scripts/Push Button.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ButtonAxisLock : MonoBehaviour
|
||||
{
|
||||
public Transform buttonDirectionRoot;
|
||||
|
||||
public float minX = 0f;
|
||||
public float maxX = 0.02f;
|
||||
public float minY = 0f;
|
||||
public float maxY = 0f;
|
||||
public float minZ = 0f;
|
||||
public float maxZ = 0f;
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
Vector3 localPos = buttonDirectionRoot.InverseTransformPoint(transform.position);
|
||||
|
||||
localPos.x = Mathf.Clamp(localPos.z, minX, maxX);
|
||||
localPos.y = Mathf.Clamp(localPos.z, minY, maxY);
|
||||
localPos.z = Mathf.Clamp(localPos.z, minZ, maxZ);
|
||||
|
||||
transform.position = buttonDirectionRoot.TransformPoint(localPos);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6faa56fe20fbd1b4fa28a756a4d9ffb6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class SpringyButtonPhysics : MonoBehaviour {
|
||||
public Transform buttonDirectionRoot;
|
||||
|
||||
public float minX = 0f;
|
||||
public float maxX = 0f;
|
||||
public float minY = 0f;
|
||||
public float maxY = 0f;
|
||||
public float minZ = 0.005f;
|
||||
public float maxZ = 0f;
|
||||
|
||||
|
||||
[Header("Spring Settings")]
|
||||
public float springForce = 300f; // how strong it returns
|
||||
public float damping = 8f; // prevents vibration
|
||||
|
||||
private Rigidbody rb;
|
||||
private Vector3 restLocalPos;
|
||||
|
||||
void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
rb.useGravity = false;
|
||||
|
||||
// initial local rest position
|
||||
restLocalPos = buttonDirectionRoot.InverseTransformPoint(transform.position);
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
// 1. Local pos
|
||||
Vector3 localPos = buttonDirectionRoot.InverseTransformPoint(transform.position);
|
||||
|
||||
// 2. Spring in LOCAL space
|
||||
Vector3 spring = (restLocalPos - localPos) * springForce;
|
||||
|
||||
// 3. Damping also must be in LOCAL space!!
|
||||
Vector3 localVelocity = buttonDirectionRoot.InverseTransformDirection(rb.velocity);
|
||||
localVelocity *= damping;
|
||||
spring -= localVelocity;
|
||||
|
||||
// 4. Convert spring to WORLD space
|
||||
Vector3 worldSpring = buttonDirectionRoot.TransformDirection(spring);
|
||||
|
||||
// 5. Apply
|
||||
rb.AddForce(worldSpring, ForceMode.Acceleration);
|
||||
|
||||
// --- 3. Compute new local pos after physics ---
|
||||
Vector3 newLocalPos = buttonDirectionRoot.InverseTransformPoint(transform.position);
|
||||
//Debug.Log(spring);
|
||||
// --- 4. Clamp to allowed ranges ---
|
||||
newLocalPos.x = Mathf.Clamp(newLocalPos.x, minX, maxX);
|
||||
newLocalPos.y = Mathf.Clamp(newLocalPos.y, minY, maxY);
|
||||
newLocalPos.z = Mathf.Clamp(newLocalPos.z, minZ, maxZ);
|
||||
|
||||
// --- 5. Convert back to world and move via Rigidbody ---
|
||||
Vector3 worldPos = buttonDirectionRoot.TransformPoint(newLocalPos);
|
||||
rb.MovePosition(worldPos);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33e7127f1ef74754f93e1b2f236a7426
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user