Commit 66003e68 authored by Tanner Grehawick's avatar Tanner Grehawick
Browse files

add GetButtonPressed and GetButtonReleased

parent 8d13b79d
fileFormatVersion: 2
guid: 2057902e730664aacbc88367b9c3b892
folderAsset: yes
timeCreated: 1486687237
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -41,7 +41,7 @@ public class InputAxisState{
}
}
public class InputManager : MonoBehaviour {
public class InputManager : SingletonBehaviour<InputManager> {
public InputAxisState[] inputs;
public InputState inputState;
......
......@@ -10,12 +10,14 @@ using System.Collections.Generic;
*/
public class ButtonState{
public bool last;
public bool value;
public float holdTime = 0;
}
public class InputState : MonoBehaviour {
[HideInInspector]
public Directions direction = Directions.Right;
private Dictionary<Buttons,ButtonState> buttonStates = new Dictionary<Buttons, ButtonState>();
......@@ -25,7 +27,7 @@ public class InputState : MonoBehaviour {
buttonStates.Add (key, new ButtonState ());
}
var state = buttonStates[key];
state.last = state.value;
if(state.value && !value){//key has been released
state.holdTime = 0;
}else if(state.value && value){//key is being held down
......@@ -34,6 +36,26 @@ public class InputState : MonoBehaviour {
state.value = value;
}
public bool GetButtonPressed(Buttons button) {
if (buttonStates.ContainsKey(button)) {
ButtonState state = buttonStates[button];
return state.value && !state.last;
}
else {
return false;
}
}
public bool GetButtonReleased(Buttons button) {
if (buttonStates.ContainsKey(button)) {
ButtonState state = buttonStates[button];
return !state.value && state.last;
}
else {
return false;
}
}
public bool GetButtonValue(Buttons key){
if (buttonStates.ContainsKey (key)) {
return buttonStates [key].value;
......
m_EditorVersion: 5.3.5f1
m_StandardAssetsVersion: 0
m_EditorVersion: 5.5.0xf3Linux
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment