Пример #1
0
    void Shoot()
    {
        muzzleFlash.Play();
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            // only occurs if we hit something with raycast.
            Debug.Log(hit.transform.name);

            EndScript targetBoss = hit.transform.GetComponent <EndScript> ();
            if (targetBoss != null)                // if the target is the target that i was loooking for
            {
                targetBoss.BossTakeDamage(damage); // since TakeDamage is public, we could use it off of this file
            }

            Target1 target = hit.transform.GetComponent <Target1> ();
            if (target != null)               // if the target is the target that i was loooking for
            {
                target.TakeDamage(damage);    // since TakeDamage is public, we could use it off of this file
            }

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

            GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impactGO, 2f);
        }
    }
Пример #2
0
    void Shoot()
    {
        muzzleflash.Play();
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, Range))
        {
            Debug.Log(hit.transform.name);

            Target target = hit.transform.GetComponent <Target>();
            if (target != null)
            {
                target.TakeDamage(Damage);
            }

            Target1 target1 = hit.transform.GetComponent <Target1>();
            if (target1 != null)
            {
                target1.TakeDamage(Damage);
            }

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

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