Instead of using Input.GetButton("Fire1") why are we using Coroutine?

Like this:-

if (Input.GetButtonDown(“Fire1”))
{
GameObject laser_R = Instantiate(LaserPrefab, LaserPos_R, Quaternion.identity) as GameObject;
laser_R.GetComponent().velocity = new Vector2(0, ProjectileSpeed);

        GameObject laser_L = Instantiate(LaserPrefab, LaserPos_L, Quaternion.identity) as GameObject;
        laser_L.GetComponent<Rigidbody2D>().velocity = new Vector2(0, ProjectileSpeed);

        Destroy(laser_L, 1.5f);
        Destroy(laser_R, 1.5f);
    }
    else if (Input.GetButton("Fire1") && Time.time>FiringPeriod)
    {
        GameObject laser_R = Instantiate(LaserPrefab, LaserPos_R, Quaternion.identity) as GameObject;
        laser_R.GetComponent<Rigidbody2D>().velocity = new Vector2(0, ProjectileSpeed);

        GameObject laser_L = Instantiate(LaserPrefab, LaserPos_L, Quaternion.identity) as GameObject;
        laser_L.GetComponent<Rigidbody2D>().velocity = new Vector2(0, ProjectileSpeed);

        Destroy(laser_L, 1.5f);
        Destroy(laser_R, 1.5f);
    }

The result is the same:

Hi,

In many cases, there are multiple ways to make something work in Unity. Your solution is as fine as the one with the coroutine. Rick wants to teach his students a variety of techniques.


See also:

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

Privacy & Terms