1
0
forked from cgvr/DeltaVR

more wires to archery range, connecting buttons

This commit is contained in:
2026-01-11 14:47:39 +02:00
parent a23f40787e
commit 991f7d73b9
5 changed files with 52 additions and 8 deletions

View File

@@ -8,9 +8,14 @@ public class PushableButton : MonoBehaviour
public event OnButtonPressedDelegate OnButtonPressed;
public bool startDown;
public Transform movableParts;
public float moveDuration = 0.25f;
public Transform wire;
public Material wireActiveMaterial;
public Material wireInactiveMaterial;
private float upPositionY;
private float downPositionY;
private bool isButtonDown;
@@ -25,7 +30,12 @@ public class PushableButton : MonoBehaviour
// Start is called before the first frame update
void Start()
{
if (startDown)
{
// Dont call Activate, we dont want to change wire material here
movableParts.DOLocalMoveY(downPositionY, moveDuration);
isButtonDown = true;
}
}
// Update is called once per frame
@@ -38,15 +48,30 @@ public class PushableButton : MonoBehaviour
{
if (!isButtonDown && collision.gameObject.tag.EndsWith("Hand"))
{
movableParts.DOLocalMoveY(downPositionY, moveDuration);
isButtonDown = true;
Activate();
OnButtonPressed?.Invoke();
}
}
public void MoveButtonUp()
private void Activate()
{
movableParts.DOLocalMoveY(downPositionY, moveDuration);
isButtonDown = true;
foreach (MeshRenderer meshRenderer in wire.GetComponentsInChildren<MeshRenderer>())
{
meshRenderer.material = wireActiveMaterial;
}
}
public void Deactivate()
{
movableParts.DOLocalMoveY(upPositionY, moveDuration);
isButtonDown = false;
foreach (MeshRenderer meshRenderer in wire.GetComponentsInChildren<MeshRenderer>())
{
meshRenderer.material = wireInactiveMaterial;
}
}
}