In my code, I made a local variable of type coroutine as below :-
void ShootLaser()
{
if (Input.GetButtonDown("Fire1"))
{
Coroutine laserCoroutine = StartCoroutine(FireContinuosly());
}
else if(Input.GetButtonUp("Fire1"))
{
StopCoroutine(laserCoroutine);
}
}
But this local laserCoroutine isn’t working…WHY?
And why do even i need to store it in a variable? just typing StopCoroutine(FireContinously());
won’t work??
Also I’m not getting what is the use of yield
keyword before the return
keyword and y do we use new
keyword in various places(like WaitForSeconds and Vector)
One more thing…why Coroutines use a special way to start( StartCoroutine()
) and same for stopping it? Why can’t simply calling them completes our work?? And why is the type of Coroutines functions is IEnumerator
and not Coroutine
?
Bunch of questions plz help