- Home /
Question is off-topic or not relevant
WaitForSeconds before reload not working?
Hello, i am working working on a shooter and I need the game to wait for a few seconds, say 5, when the reload command is pressed to give time for my reload animation to play. I am trying to use the code below, which i constructed after consulting the scripting reference and a few other posts in the forums, but it does not work, I don't get any error messages but the game just reloads instantly without raking notice of the delay. Any help on this would be greatly appreciated, Thanks you.
Jack
Here is my code.
void Reload()
{
reloadtimer(5.0f);
Player.GetComponentInChildren<PlayerAmmo>().clipsize = Player.GetComponentInChildren<PlayerAmmo>().clipmax;
Player.GetComponentInChildren<PlayerAmmo>().AmmoCount -= Player.GetComponentInChildren<PlayerAmmo>().clipsize;
}
IEnumerator reloadtimer(float delay)
{
yield return new WaitForSeconds(delay);
}
Answer by Julien-Lynge · May 07, 2013 at 12:15 AM
FYI, UnityAnswers (UA) is not Quality Assurance (QA) - it is up to you to write and bugfix your own code. We're more than willing to help you learn Unity, so please start with these resources and do a bit of research on your own:
Please check the documentation for IEnumerators and the documentation for StartCoroutine, which you will need to understand and use. You are not using IEnumerators correctly.
Follow this Question
Related Questions
IEnumerator manipulates variable in android build 1 Answer
Proper Way to Wait in C# 1 Answer
WaitForSeconds Not Working [SOLVED] 2 Answers
Return without Break 1 Answer