예제 #1
0
    public void Fire()
    {
        --currentClip;
        UpdateAmmoText();
        int rndIndex = Random.Range(0, SFX_DEFAULT_FIRE.Length);

        audioSource.PlayOneShot(SFX_DEFAULT_FIRE[rndIndex], SETTINGS.MASTER_VOLUME * SETTINGS.SFX_VOLUME);

        RaycastHit2D hit;

        //if mouse
        if (Aim.USE_MOUSE)
        {
            hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
        }
        else //leap
        {
            hit = Physics2D.Raycast(aim.position, Vector2.zero);
        }
        if (hit)
        {
            // if a hit was registered at all...
            if (hit.collider.tag == "Target")
            {
                Target t = hit.transform.gameObject.GetComponent <Target>();
                t.TakeDamage(damage);
            }
            if (hit.collider.tag == "Powerup" && GLOBAL.POWERUP_ACTIVE == false)
            {
                Powerup pu = hit.transform.gameObject.GetComponent <Powerup>();
                pu.EnablePowerup();
            }
        }
    }