Ejemplo n.º 1
0
    public void apply()
    {
        GameObject effectBomb = (GameObject)Instantiate(Resources.Load("PickupBomb"), transform.position, Quaternion.identity);
        ColorLerp  bombColor  = effectBomb.transform.GetChild(0).gameObject.GetComponent <ColorLerp>();

        bombColor.startColor = effectColor;
        bombColor.endColor   = new Color(effectColor.r, effectColor.g, effectColor.b, 0);

        if (ctrl.bombs < MAX_BOMBS)
        {
            ctrl.bombs += bombAdd;
        }
        else if (ctrl.bombs >= MAX_BOMBS && bombAdd > 0)
        {
            ctrl.changeMultiplier(3);   //increment multiplier by 1
        }
        if (ctrl.getHealth() < MAX_HEALTH)
        {
            ctrl.setHealth(ctrl.getHealth() + healthAdd);
        }
        else if (ctrl.getHealth() >= MAX_HEALTH && healthAdd > 0)
        {
            ctrl.changeMultiplier(3);   //increment mulitiplier by 1
        }
        HelperFunctions.playSound(ref _audioSource, pickUpSound);
        foreach (GameObject g in HelperFunctions.getChildren(gameObject.transform))
        {
            if (g.GetComponent <SpriteRenderer>() != null)
            {
                g.GetComponent <SpriteRenderer>().color = Color.clear;
            }
        }
        pickedUp = true;
        Destroy(gameObject, 0);
    }
Ejemplo n.º 2
0
    private void Fire()
    {
        _audioSource.pitch  = Random.Range(.4f, 1f);
        _audioSource.volume = Random.Range(.3f, .6f);
        HelperFunctions.playSound(ref _audioSource, fireSound);
        RaycastHit2D[] toKill     = Physics2D.RaycastAll(transform.position, HelperFunctions.lineVector(transform.rotation.eulerAngles.z), 20);
        bool           miss       = true;
        int            enemiesHit = 0;

        foreach (RaycastHit2D e in toKill)
        {
            if (e.collider.CompareTag("Enemy"))
            {
                Enemy enemy = e.collider.gameObject.GetComponent <Enemy>();
                if (enemy.isOnScreen() && !enemy.invincible)
                {
                    enemy.takeDamage(100, laserColor.startColor);
                    ParticleSystem.MainModule enemyParticles = enemy.GetComponentInChildren <ParticleSystem>().main;
                    enemyParticles.startColor = particleColor;
                    ++enemiesHit;
                    miss = false;
                }
            }
            else if (e.collider.CompareTag("Pickup"))
            {
                e.collider.GetComponent <Pickup>().apply();
                miss = false;
            }
            else if (e.collider.CompareTag("Target"))
            {
                e.collider.GetComponent <Target>().activate();
            }
        }

        if (ctrl.survival)
        {
            //There are three cases: no hits, some hits, and only pickups hit
            //no hits should call change multiplier
            //some hits should call change multiplier
            //only pickups hit (!miss && enemiesHit == 0) should not call changeMultiplier
            if ((miss) || (!miss && enemiesHit > 0))
            {
                ctrl.changeMultiplier(enemiesHit);
            }
        }

        charge = 0;

        laser.transform.position = transform.position + HelperFunctions.lineVector(transform.rotation.eulerAngles.z, laser.transform.localScale.x * 0.5f);

        laser.transform.rotation = transform.rotation;
        laserColor.startColorChange();
    }