Esempio n. 1
0
    void Shoot()
    {
        CameraShaker.GetInstance("Main Camera").ShakeOnce(1.5f, 2f, 0, 0.5f);

        //Bullet spread calculations
        Vector3    deviation3D = Random.insideUnitCircle * accuracy;
        Quaternion rot         = Quaternion.LookRotation(Vector3.forward + deviation3D);
        Vector3    fwd         = transform.rotation * rot * Vector3.forward;

        bool       enemyHit = false;
        RaycastHit hit;

        if (Physics.Raycast(trans.position, fwd, out hit))
        {
            if (hit.transform.CompareTag("Enemy"))
            {
                Destroy(hit.transform.gameObject, 0.5f);
                hit.transform.GetComponent <Enemy>().dying = true;
                enemyHit = true;
                StartCoroutine(ShowHitMark(false));

                //blood splatter effect
                GameObject impact    = Instantiate(bodyImpact, hit.transform.position, bodyImpact.transform.rotation);
                float      randScale = Random.Range(2f, 3f);
                impact.transform.localScale = (new Vector3(randScale, randScale, randScale));
                Destroy(impact, 1f);
            }
            else if (hit.transform.CompareTag("Truck"))
            {
                hit.transform.GetComponent <Truck>().lives--;
                StartCoroutine(ShowHitMark(true));
                float randHitSound = Random.Range(0f, 1f);
                if (randHitSound > 0.65f)
                {
                    AudioFW.PlayRandomPitch("MetalHit");
                }
            }
        }
        GameObject newShot = Instantiate(mGShot, trans.position, trans.parent.rotation);

        newShot.GetComponent <Rigidbody>().AddForce(fwd * shootForce, ForceMode.Impulse);
        if (enemyHit)
        {
            Destroy(newShot, 0.1f);
            EnemyManager.enemiesLeft--;
            kills++;
            Clipboard.instance.ChangeKills(kills.ToString());
        }
        else
        {
            Destroy(newShot, 1f);
        }

        GameObject flash = Instantiate(mFlash, trans.GetChild(0).position, Quaternion.identity);

        Destroy(flash, 0.02f);
    }
Esempio n. 2
0
    IEnumerator ShowHitMark(bool hitSound)
    {
        Cursor.SetCursor(cursorHit, new Vector2(20, 20), CursorMode.Auto);
        yield return(new WaitForSeconds(0.1f));

        if (!hitSound)
        {
            AudioFW.PlayRandomPitch("HitMarker");
        }
        yield return(new WaitForSeconds(0.1f));

        Cursor.SetCursor(cursor, new Vector2(20, 20), CursorMode.Auto);
    }
Esempio n. 3
0
    private void FixedUpdate()
    {
        if (dying)
        {
            col.enabled = false;
            anim.SetTrigger("Die");
            transform.localEulerAngles = dieRot;
        }
        int   rand = Random.Range(1, 300);
        float dist = Vector3.Distance(transform.position, new Vector3(0, 30, 0));

        if (rand == 1 && dist < 150)
        {
            GameObject flash = Instantiate(mzlFlash, barrelEnd.transform.position, Quaternion.identity, barrelEnd.transform);
            AudioFW.PlayRandomPitch("EnemyRifle");
            Destroy(flash, 0.2f);
        }
    }
Esempio n. 4
0
 void StopShootSounds()
 {
     AudioFW.StopLoop("BurstLoop");
     AudioFW.PlayRandomPitch("BurstTail");
 }