40 lines
966 B
C#
40 lines
966 B
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class HeldInteractions : MonoBehaviour
|
|
{
|
|
[Header("Flashlight")]
|
|
public GameObject Flashlight;
|
|
public AudioSource FlashlightToggleSfx;
|
|
public InputActionProperty FlashlightAction;
|
|
[Header("Misc")]
|
|
public GameObject Map;
|
|
public InputActionProperty MapAction;
|
|
|
|
public bool OffHandFree => !Map.activeSelf;
|
|
|
|
bool justToggledLight;
|
|
|
|
private void Update()
|
|
{
|
|
var toggledMap = MapAction.action.WasPressedThisFrame();
|
|
if (toggledMap) {
|
|
Map.SetActive(!Map.activeSelf);
|
|
}
|
|
|
|
var lightThreshold = 0.9f;
|
|
var toggledLight = FlashlightAction.action.ReadValue<float>();
|
|
if (toggledLight > lightThreshold && !justToggledLight) {
|
|
justToggledLight = true;
|
|
|
|
Flashlight.SetActive(!Flashlight.activeSelf);
|
|
|
|
FlashlightToggleSfx.Stop();
|
|
FlashlightToggleSfx.pitch = Random.Range(0.9f, 1.1f);
|
|
FlashlightToggleSfx.Play();
|
|
}
|
|
if (toggledLight < lightThreshold)
|
|
justToggledLight = false;
|
|
}
|
|
}
|