Hi Nina,
I figured out the error, so previously, I wrapped the if (Input.GetButtonDown(“Fire1”)) in the while(true) statement and it looked something likes this
IEnumerator FireRapidly()
{
while (true) {
if (Input.GetButtonDown("Fire1"))
{
GameObject laser = Instantiate(laserPrefab, transform.position, Quaternion.identity) as GameObject;
laser.GetComponent<Rigidbody2D>().velocity = new Vector2(0, projectileSpeed);
yield return new WaitForSeconds(projectileFiringPeriod);
}
}
While the startCoroutine was only inside the Fire Method with no if statement and it look like this
private void Fire()
{
Firingcoroutine = StartCoroutine (FireRapidly());
if(Input.GetButtonUp("Fire1"))
{
StopCoroutine(Firingcoroutine);
}
This cause the Unity Editior to freeze and not respond the moment I clicked on play, thus I had to force quit using windows TaskManager
The solution was as shown the lecture is to take the
if (Input.GetButtonDown(“Fire1”)) and move it to the Fire method, then put the Firingcoroutine = StartCoroutine (FireRapidly()); inside of it and should look like this
private void Fire()
{
if (Input.GetButtonDown("Fire1"))
{
Firingcoroutine = StartCoroutine(FireRapidly());
}
if(Input.GetButtonUp("Fire1"))
{
StopCoroutine(Firingcoroutine);
}
}
This was an oversight on my part and not a problem in the lecture, I apologize for that.