Exemplo n.º 1
0
    IEnumerator Shoot()
    {
        float shootStep  = 0.35f;
        float shootTimer = 0.0f;

        while (true)
        {
            if (state == 2)
            {
                if (shootTimer >= shootStep && !pHealth.dead)
                {
                    aud.PlaySFX("enemyGun");
                    ps.Play();
                    pHealth.TakeDamage(TESTGunDamage);
                    StartCoroutine(pEffects.BloodFlash());
                    shootTimer = 0;
                }
                else
                {
                    shootTimer += Time.deltaTime;
                }
            }
            else
            {
                shootTimer = 0.75f;
            }
            yield return(new WaitForEndOfFrame());
        }
    }
Exemplo n.º 2
0
    void AttackUpdate()
    {
        transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));
        if (!PlayerInRange())
        {
            aud.PlaySFX("enemyPatrol");
            state           = 0;            //switch to chase phase(??? NOTE: May want to give it a 3 second or so timer so the player can book it in time)
            shootGunCurrent = shootGunStep; //this way the first shot is the exact frame that the player is within range next time.
            if (!changeBackToChaseInProgress)
            {
                changeBackToChaseInProgress = true;
                StartCoroutine(RevertBackToChaseMode());
            }
        }
        //potentially use the same step/current system to shoot? its nicer than a coroutine
        else
        {
            //if we reach this while waiting for the revert, then we can cancel it this way.
            if (changeBackToChaseInProgress)
            {
                changeBackToChaseInProgress = false;
            }

            if (shootGunCurrent >= shootGunStep && !pHealth.dead)
            {
                //shoot gun
                aud.PlaySFX("enemyGun");
                ps.Play();
                pHealth.TakeDamage(damageToDeal);
                StartCoroutine(pEffects.BloodFlash());
                shootGunCurrent = 0;
            }
            else
            {
                shootGunCurrent += Time.deltaTime;
            }
        }
    }