예제 #1
0
    public void Shoot()
    {
        _flash.Play();
        _audio.Play();
        RaycastHit hit;
        Vector3    dir = new Vector3(_flash.transform.forward.x, _flash.transform.forward.y - 0.01f, _flash.transform.forward.z);

        if (Physics.Raycast(_flash.transform.position,
                            dir, out hit, 200f))
        {
            GameObject impact = Instantiate(_impact, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impact, 0.1f);
            HP     hp     = hit.transform.GetComponent <HP>();
            Armour armour = hit.transform.GetComponent <Armour>();
            if (armour != null && armour.enabled)
            {
                armour.GetDamage(_damage);
                return;
            }
            if (hp != null && hit.transform.tag != transform.tag)
            {
                hp.GetDamage(_damage);
            }
        }
    }
예제 #2
0
    private void Shoot()
    {
        if (_ammo == 0)
        {
            return;
        }
        _flash.Play();
        _audio.Play();
        _ammo--;
        _ammoInfo.text = "Ammo : " + _ammo;
        RaycastHit hit;

        if (Physics.Raycast(_cam.transform.position, _cam.transform.forward, out hit, _weapon.GetRange()))
        {
            GameObject impact = Instantiate(_impact, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impact, 0.1f);
            Rigidbody rb = hit.transform.GetComponent <Rigidbody>();
            if (rb != null)
            {
                rb.AddForce(-hit.normal * 100);
            }
            HP hp = hit.transform.GetComponent <HP>();
            if (hp != null)
            {
                hp.GetDamage(_weapon.GetDamage());
            }
        }
    }
예제 #3
0
    private void Explode()
    {
        _audio.Play();
        GameObject part = Instantiate(_exploParticle, transform.position, Quaternion.identity);

        Destroy(part, 0.7f);
        Collider[] colliders = Physics.OverlapSphere(transform.position, _radius);
        foreach (var coll in colliders)
        {
            HP hp = coll.GetComponent <HP>();
            if (coll.CompareTag("Enemy") && hp != null)
            {
                hp.GetDamage(_damage);
            }
        }

        _hasExploded = true;
        Destroy(gameObject, 1);
    }