
Comments

staminometer lever
First you need to add a new GameObject and put it into the hud object and now name it into Lever and now your gonna need to add a new component and search up Image as a new component and now put the Lever1 for the staminometer (i put the download link to the lever) as a image and your gonna have to put the Lever object next to the staminometer object and now create a new script called LeverSwitch and type in the LeverSwitch this code
using UnityEngine;
using UnityEngine.UI; // Required for UI components
public class LeverSwitch : MonoBehaviour
{
  public Image uiImage;Â
  public Sprite normalSprite;    Â
  public Sprite shiftSprite;     Â
  Â
  [Header("Audio Settings")]
  public AudioSource audioSource;Â
  public AudioClip buttonPress;
  public AudioClip buttonRelease; // Added this slot for your release sound    Â
  void Update()
  {
    // Swaps and plays sound when Shift is pressed down
    if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
    {
      uiImage.sprite = shiftSprite;
      if (audioSource != null && buttonPress != null)
      {
        audioSource.PlayOneShot(buttonPress);
      }
    }
    // Swaps back and plays sound when Shift is released
    if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift))
    {
      uiImage.sprite = normalSprite;
      // Plays the release sound clip
      if (audioSource != null && buttonRelease != null)
      {
        audioSource.PlayOneShot(buttonRelease);
      }
    }
  }
}
and once you did that add a new component again and search up LeverSwitch and once you did that
add Ui Image as a Lever object in hierarchy and drag it into Ui Image next to the inspector
Normal Sprite is going to be Lever1
Shift Sprite is going to be Lever2
and now add a component called Audio Source
now the Audio Settings
Audio Source is going to be Lever object in hierarchy and drag it into Audio Source next to the inspector
Button Press is going to be Sfx_Button_Press
and Button Release is going to be Sfx_Button_Unpress
and thats it!
you have successfully have a lever switch when ever you run!
(and adding a sound when ever you press shift is optional)