How to make enemy get hit when I choose correct answer on math game
I got a question and 4 choices on math game for player. When player choose a correct choice, Enemy will get hit by player.
When player choose incorrect choice, Enemy will hit player.
No offense but what you’re asking is pretty basic, and I would suggest watching tutorials on the matter, since they can show you, instead of me typing… basically…
But… legal disclaimer out of the way, You obviously will need your UI buttons or maybe you mean actual buttons like on a keyboard or gamePad? If UI, you gotta make functions that read :
public void OnClickRightAnswer()
{
PlayerClass.DamageCurrentEnemy(Player.damage);
}
And then within the script that houses the UI calls(button click), just setup it up in the inspector that onClick() calls the function OnClickRightAnswer(). Or if you mean actual key presses:
if (Input.GetKeyDown(KeyCode.K))
{
DamageCurrentEnemy(damage);
}
And if you mean how to get the scripts to communicate, you could use GetComponent(), but I’d highly advise against that, and check out my post:
But more-over, I would suggest tutorials. Just do as they do, make sure it works, then tear it apart and play with the code to fully understand it