This question was
closed Nov 18, 2016 at 07:18 PM by
Vekosava for the following reason:
SOLVED
[SOLVED] How to check if Player Input matches KeyCode (Spell System)
Hey guys!
I started working on some spell system and what I want is to have PlayerSpells class which will handle List of all Spells that Player has and loop through them every frame and check if player input matches KeyCode variable that is given to each spell. Currently I'm stuck with this so, If anyone can help, I would appreciate it!
Scripts:
PlayerSpells Class
using UnityEngine;
using System.Collections.Generic;
public class PlayerSpells : MonoBehaviour {
public List<Spell> spells = new List<Spell> ();
void Update () {
for (int i = 0; i < spells.Count; i++) {
if (Input.inputString == spells[i].key.ToString()) {
spells [i].Cast ();
Debug.Log ("Action!");
}
}
}
}
Spells Class
using UnityEngine;
public class Spell : MonoBehaviour {
public KeyCode key;
public void Cast () {
}
}
I'm not getting any Log in console, so I'm not sure if I'm not checking and comparing player input on the right way or what.
Thanks!
Comment