- Home /
C# Noob Confused About IEnumerator
Hello All... I'm messing around with a Third person Shooter, Atm the character reloads Instantly so its very unrealistic so i created a float
public float reloadTime;
then inside my reload function i added
yield return new WaitForSeconds(reloadTime);
But this causes issues so i changed Void Reload() to IEnumerator Reload() The Error goes away but now the reload function isn't being called.
This is the reload Function "NON edited"
public void Reload() {
Debug.Log("Reload [" + weaponsSet[weaponIndex].weaponName+"]");
int needBullets = (weaponsSet[weaponIndex].clipSize - weaponsSet[weaponIndex].currentBulletsCount);
if (weaponsSet[weaponIndex].haveBullets >= needBullets){
weaponsSet[weaponIndex].haveBullets -= needBullets;
weaponsSet[weaponIndex].currentBulletsCount = weaponsSet[weaponIndex].clipSize;
}
else{
weaponsSet[weaponIndex].currentBulletsCount = weaponsSet[weaponIndex].haveBullets;
weaponsSet[weaponIndex].haveBullets = 0;
}
}
I really only the basics of Javascript so C# is really confusing me and i don't understand what im doing wrong.
Answer by PAEvenson · Aug 26, 2013 at 02:53 PM
in order to call a coroutine you need to send it through StartCoroutine like so:
StartCoroutine(Reload());
Here is a link to the reference page - http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.StartCoroutine.html
Unity Gems has a much better article on coroutines, for C# (and not only) "confused noobs" :)
@ArkaneX Thanks for the link to Unity Gems, I have quite enjoyed the past 2 hours reading and watching videos there :)
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Help needed on creating a options menu 1 Answer
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
Make Health script lose health when certain animation is played? 1 Answer