Example #1
0
    void Shoot()
    {
        GameObject fxShoot = Instantiate(fxShootPrefab, shootPos.position, shootPos.rotation * Quaternion.Euler(0f, 0f, Random.Range(0f, 90f))); //Quaternion.Euler(0f, 0f, Random.Range(0f, 90f) ) );

        fxShoot.transform.parent = gameObject.transform;
        Destroy(fxShoot, 1f);
        // muzzleFlash.Play();
        gunAnim.Shoot(true);
        audioManager.Play("SHOOT");

        RaycastHit hit;

        // if (Physics.Raycast(Camera.main.ScreenPointToRay(location), out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Terrain")))
        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range, ~ignoreLayer))
        {
            // Debug.Log( hit.transform.name );
            Target      target  = hit.transform.GetComponent <Target>();
            EnemyStatus eStatus = hit.transform.GetComponent <EnemyStatus>();
            if (target != null)
            {
                target.TakeDamage(damage);
            }

            if (eStatus != null)
            {
                eStatus.AdjustHealth(-damage);
            }

            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(hit.normal * impactForce);
            }

            GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impactGO, 2f);
        }
    }