Question by
Sauro_98 · Mar 03, 2016 at 01:02 AM ·
scripting problem
C# coroutine not working as expected
I wanted to use a coroutine to make the player wait a little before shooting a new bullet but it never gets past the yield. Here's the code
protected override void Start () {
base.Start ();
animator = GetComponent<Animator> ();
score = GameManager.instance.playerScore;
playerLives = GameManager.instance.playerLife;
}
void Update(){
int horizontal = (int)Input.GetAxisRaw("Horizontal");
AttemptMove (horizontal, 0);
if (Input.GetKeyDown ("space")) {
Vector3 shootPosition = transform.position + new Vector3 (0, 0.5f, 0);
Instantiate (bullet, shootPosition, Quaternion.identity);
StartCoroutine(Shoot());
}
}
IEnumerator Shoot(){
Debug.Log("Start");
yield return new WaitForSeconds (shootingTimeDelay);
Debug.Log("End");
}
It never prints End. I don't get what is wrong
Comment
Your answer
Follow this Question
Related Questions
Why Collider2D size Y changes affects child object position 0 Answers
Why is my cube not following the other the way i want ? 1 Answer
How to Undo a lot of created objects at once? [Solved] 1 Answer
How to make hundrenths of seconds in C#? 1 Answer
Sprite renderers not rendering on Instatiated objects 2d 0 Answers