About 'Repeat Fire Coroutine'!

Hello Rick, could you please clarify what’s the difference between your way in the lecture and the one below?

 private void Fire()
    {
        if (Input.GetButton("Fire1"))
        {
            StartCoroutine(FireContinuously());
        }
}
IEnumerator FireContinuously()
    {
            GameObject laser = Instantiate(laserPrefab, transform.position, Quaternion.identity) as 
            GameObject;
            laser.GetComponent<Rigidbody2D>().velocity = new Vector2(0, projectileSpeed);
            yield return new WaitForSeconds(projectileFiringPeriod);
        
    }

Top of the morning, guys! First of all, thanks for the course, it’s going great so far. Second, I should apologize for my English, it’s not my first language. :slight_smile:

To the point, I would be really grateful if I had your opinion on my solution to the fire rate coroutine issue. I’m sure it’s not the best, but I just want to know EVERYTHING!:slight_smile:

Thanks and have a good day!
12%20PM

Privacy & Terms