Since Unity’s Input manager is a little rough around the edges I thought I’d write my own. I’m working on a gamepad/controller script that
just like Input.GetButtonDown().
It functions fine, but I can’t help but think there’s a better way of doing it.
With this method, I have to create 2 public static variables just for one trigger.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class InputManager {
// The variable names have lowercase L's in the script, but on the web it looks like iMessage,
// which confuses readability; L refering to the left trigger as opposed to right.
public static bool LMessage = false;
public static bool LMessageSent = false;
public static bool LeftTriggerDown(float triggerValue = .9f, float releaseValue = .0001f)
{
if (Input.GetAxis("Left Trigger") > triggerValue && messageSent == false)
{
LMessage = true;
LMessageSent = true;
return LMessage;
}
else if (Input.GetAxis("Left Trigger") < releaseValue)
{
LMessage = false;
LMessageSent = false;
return LMessage;
}
else { return false; }
}
Assuming this function is only going to be called in the Update() function, is there another way of organizing this code? Preferably using local variables? I don’t like having those public-statics…
Thanks in advance!