void OnTriggerEnter2D(Collider2D collider)
    {
        Laser   missile = collider.gameObject.GetComponent <Laser>();
        Meteor  meteor  = collider.gameObject.GetComponent <Meteor>();
        Powerup powerup = collider.gameObject.GetComponent <Powerup>();

        // Laser was fired and collides with player
        if (missile)
        {
            // If shield is hit, negate the damage and destroy the missile
            if (Powerup.GetShield())
            {
                ShieldDown();
                missile.Hit();
            }
            // Else take damage
            else
            {
                health -= missile.GetDamage();
                missile.Hit();
                HealthCheck();
            }
        }

        // Meteor collides with player
        if (meteor)
        {
            // If shield is hit, negate the damage and destroy the meteor
            if (Powerup.GetShield())
            {
                ShieldDown();
                meteor.Hit();
            }
            // Else take damage
            else
            {
                health -= meteor.GetDamage();
                meteor.Hit();
                HealthCheck();
            }
        }

        // If player collects a shield powerup
        if (powerup && collider.gameObject.name.Contains("shieldPowerup"))
        {
            ShieldUp(powerup);
        }

        // If player collects a speed powerup
        if (powerup && collider.gameObject.name.Contains("speedPowerup"))
        {
            SpeedBoostOn(powerup);
        }
    }
 void ShieldUp(Powerup powerup)
 {
     // Only display shield image if there isn't one active already (prevents duplicates)
     if (!Powerup.GetShield())
     {
         shieldImage = Instantiate(shieldPrefab, transform.position, Quaternion.identity) as GameObject;
     }
     Powerup.SetShield(true);
     AudioSource.PlayClipAtPoint(shieldUp, transform.position);
     powerup.Collected();
 }
    void Update()
    {
        // Restrict player to game space
        float newx = Mathf.Clamp(transform.position.x, xmin, xmax);

        transform.position = new Vector3(newx, transform.position.y, transform.position.z);

        // Move left and right
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            transform.position += Vector3.left * speed * Time.deltaTime;
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
            transform.position += Vector3.right * speed * Time.deltaTime;
        }

        // If space is held down, fire lasers at a set rate
        // "Fire" refers to the method above via string
        if (Input.GetKeyDown(KeyCode.Space))
        {
            InvokeRepeating("Fire", 0.000001f, fireRate);
        }

        // If space is released, cease firing lasers
        if (Input.GetKeyUp(KeyCode.Space))
        {
            CancelInvoke("Fire");
        }

        // If speed boost expired, set speed and fire rate back to normal
        if (Powerup.GetSpeedBoost() && Time.time - globalTime >= 20f)
        {
            SpeedBoostOff();
        }

        // Set position of shield to be the same as the player
        if (Powerup.GetShield())
        {
            shieldImage.transform.position = transform.position;
        }
    }