Reputation: 9
I'm following a tutorial about health bar and mana being affected by GetKeyDown function. For some reason when I press "I" or "O" nothing occurs. Even my characters movements are immobile.
I've tried backtracking and even changing the health stats. The tutorial is from this https://www.youtube.com/watch?v=8StwNBJ5fE8
[SerializeField]
private Stat health;
[SerializeField]
private Stat mana;
private float initHealth = 100;
private float initMana = 50;
protected override void Start()
{
health.Initialize(initHealth, initHealth);
mana.Initialize(initMana, initMana);
base.Update();
}
private void GetInput()
{
direction = Vector2.zero;//reset direction
if (Input.GetKeyDown(KeyCode.I))
{
health.MyCurrentValue -= 10;
mana.MyCurrentValue -= 10;
}
if (Input.GetKeyDown(KeyCode.O))
{
health.MyCurrentValue += 10;
mana.MyCurrentValue += 10;
}
if (Input.GetKeyDown(KeyCode.W))
{
direction += Vector2.up;
}
if (Input.GetKeyDown(KeyCode.A))
{
direction += Vector2.left;
}
if (Input.GetKeyDown(KeyCode.S))
{
direction += Vector2.down;
}
if (Input.GetKeyDown(KeyCode.D))
{
direction += Vector2.right;
}
}
}
Upvotes: 0
Views: 505
Reputation: 133
Calling the function in the Update() function should produce the desired results if I am understanding your question correctly.
EDIT: Erased unnecessary response
Upvotes: 1