Don't understand logic of this section

Here is the code:
void ProcessFiring()
{
if (Input.GetButton (“Fire1”))
{
SetLasersActive(true);
}
else
{
SetLasersActive(false);
}
}

void SetLasersActive(bool isActive)
{
    foreach (GameObject laser in lasers)
    {
        var emissionModule = laser.GetComponent<ParticleSystem>().emission;
        emissionModule.enabled = isActive;

    }

What I’m not getting has to do with the bool values. When fire1 is pressed, the method SetLasersActive is set to true. Since we have (bool isActive) as a parameter does this mean that the variable isActive is also set to true? And by extension does this mean emissionModule.enabled is set to true? I’m pretty sure I’m just getting hung up on this due to formatting but I want to make sure I have a grasp on the logic here.

Hi @dogsauce,

Welcome to our community! :slight_smile:

Since we have (bool isActive) as a parameter does this mean that the variable isActive is also set to true?

That’s right. When we call SetLasersActive(true); and pass on the value “true” to the SetLasersActive method, that value gets stored in isActive so we are able to use our passed on value inside the method code block.

And by extension does this mean emissionModule.enabled is set to true?

That’s exactly what happens in the code whenever SetLasersActive(true); gets called. :slight_smile:


See also:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms