--------------------------------------------------------------------------------------------------
[CreateAssetMenu(fileName ="ComboData",menuName="Custom/Combodata")]
public class ComboData : ScriptableObject
{
public string comboKey;
public string Action;
public GameObject ParticlecCombo;
}
------------------------------------------------------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class ComboSystem : MonoBehaviour
{
//public string[] comboSequences;
public ComboData[] comboData;
public float comboInputWindow = 0.5f;
private string currentInput = "";
private bool comboExecuted = false;
private float comboExecutedTime = 0f;
//Text
public TextMeshProUGUI keyInput;
public TextMeshProUGUI ExecuteInput;
void Update()
{
if (currentInput.Length > 0)
{
comboExecutedTime += Time.deltaTime;
}
foreach (ComboData combo in comboData)
{
if(currentInput.EndsWith(combo.comboKey))
{
comboExecuted = true;
ExecuteCombo(combo);
currentInput = "";
break;
}
}
if (comboExecuted && (Time.time - comboExecutedTime) > comboInputWindow)
{
comboExecuted = false;
}
if(comboExecutedTime >= comboInputWindow && currentInput.Length > 0)
{
currentInput = "";
comboExecutedTime = 0;
ExecuteInput.text = "";
keyInput.text = "";
}
if(Input.GetKeyDown(KeyCode.P))
{
currentInput += "P";
comboExecutedTime = 0;
keyInput.text = currentInput;
}
if(Input.GetKeyDown(KeyCode.K))
{
currentInput += "K";
comboExecutedTime = 0;
keyInput.text = currentInput;
}
}
void ExecuteCombo(ComboData combo)
{
Debug.Log("Combo Executed: " + combo);
ExecuteInput.text = combo.Action + " : " + combo.comboKey;
keyInput.text = "";
}
}
Comments