void Explode()
    {
        Instantiate(explosionEffect, transform.position, transform.rotation);

        //function that allows us to create a shpere that we want the objects to interact with
        //returns array
        Collider[] collidersToDestroy = Physics.OverlapSphere(transform.position, radius);
        //in the first loop we destroy and in the second we apply forces
        foreach (Collider nearbyObject in collidersToDestroy)
        {
            //destroy in pieces
            Destructible des = nearbyObject.GetComponent <Destructible>();
            if (des != null)
            {
                des.Destroy();
            }
        }

        Collider[] collidersToMove = Physics.OverlapSphere(transform.position, radius);

        foreach (Collider nearbyObject in collidersToMove)
        {
            Rigidbody rb = nearbyObject.GetComponent <Rigidbody>();
            if (rb != null)
            {
                //built in unity function
                rb.AddExplosionForce(force, transform.position, radius);
            }
        }

        Destroy(gameObject);
    }
Exemple #2
0
    void Explode()
    {
        Instantiate(explosionEffect, transform.position, transform.rotation);
        Collider[] collidersToDestroy = Physics.OverlapSphere(transform.position, radius);
        foreach (Collider nearbyObject in collidersToDestroy)
        {
            Destructible dest = nearbyObject.GetComponent <Destructible>();
            if (dest != null)
            {
                dest.Destroy();
            }
        }
        Collider[] collidersToMove = Physics.OverlapSphere(transform.position, radius);
        foreach (Collider nearbyObject in collidersToMove)
        {
            Rigidbody rb = nearbyObject.GetComponent <Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(force, transform.position, radius);
            }
        }


        Debug.Log("Boom!");
        Destroy(gameObject);
    }
    public void ExplodeLevePalette()
    {
        Instantiate(explosionEffect, transform.position, transform.rotation);
        CameraShaker.Instance.ShakeOnce(5f, 5f, .2f, 2f);
        FindObjectOfType <AudioManager>().Play("LevelPalette");
        Debug.Log("Boom from little car !");
        Collider[] collidersToDestroy = Physics.OverlapSphere(transform.position, radius);

        foreach (Collider nearbyObject in collidersToDestroy)
        {
            Destructible dest = nearbyObject.GetComponent <Destructible>();
            if (dest != null)
            {
                dest.Destroy();
                Destroy(this);
            }
        }
        Collider[] collidersToMove = Physics.OverlapSphere(transform.position, radius);

        foreach (Collider nearbyObject in collidersToMove)
        {
            Rigidbody rb = nearbyObject.GetComponent <Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(force, transform.position, radius);
                Destroy(this);
            }
        }
    }
Exemple #4
0
    void Explode()
    {
        Instantiate(explosionEffect, transform.position, Quaternion.identity);
        Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius);
        foreach (var nearbyObject in colliders)
        {
            if (nearbyObject.gameObject == FPSPlayer)
            {
                FPSPlayer.GetComponent <Target>().Die();
            }

            Rigidbody rb = nearbyObject.GetComponent <Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(explosionForce, transform.position, explosionRadius);
            }

            Destructible dest = nearbyObject.GetComponent <Destructible>();
            if (dest != null)
            {
                dest.Destroy();
            }
        }
        Destroy(gameObject);
    }
    void FireRay()
    {
        RaycastHit hit;


        Ray ray = new Ray(flameGameobject.transform.position, flameGameobject.transform.forward);

        if (Physics.Raycast(ray, out hit, 1000f))
        {
            if (hit.collider.tag == "environment" || hit.collider.tag == "Soldier")
            {
                Debug.Log("Collision with environment");
                Collider[] colliders = Physics.OverlapSphere(hit.point, explosionRadius);

                GameObject cubehit = Instantiate(GameObject.CreatePrimitive(PrimitiveType.Cube), hit.point, Quaternion.identity);
                Destroy(cubehit, 0.2f);
                foreach (Collider collider in colliders)
                {
                    Rigidbody rb = collider.GetComponent <Rigidbody>();
                    if (rb != null)
                    {
                        rb.AddExplosionForce(explosionForce, hit.point, explosionRadius);
                    }

                    Destructible dest = collider.GetComponent <Destructible>();
                    if (dest != null)
                    {
                        dest.Destroy();
                    }
                }
            }
        }
    }
    void Explosion()
    {
        if (Input.GetMouseButton(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 1000))
            {
                Collider[] colliders = Physics.OverlapSphere(hit.point, explosionRadius);

                foreach (Collider collider in colliders)
                {
                    Rigidbody rb = collider.GetComponent <Rigidbody>();
                    if (rb != null)
                    {
                        rb.AddExplosionForce(explosionForce, hit.point, explosionRadius);
                    }

                    Destructible dest = collider.GetComponent <Destructible>();
                    if (dest != null)
                    {
                        dest.Destroy();
                    }
                }
            }
        }
    }
Exemple #7
0
    void Explode()
    {
        // Show effect
        GameObject _explosion = Instantiate(explosionEffect, transform.position, transform.rotation);

        Destroy(_explosion, 3f);

        // Get nearby objects
        Collider[] _collidersToDestroy = Physics.OverlapSphere(transform.position, radius);

        foreach (Collider _nearbyObject in _collidersToDestroy)
        {
            Destructible _destructibleObject = _nearbyObject.GetComponent <Destructible>();
            if (_destructibleObject != null)
            {
                _destructibleObject.Destroy();
            }
        }

        Collider[] _collidersToMove = Physics.OverlapSphere(transform.position, radius);

        foreach (Collider _nearbyObject in _collidersToMove)
        {
            Rigidbody _rb = _nearbyObject.GetComponent <Rigidbody>();
            if (_rb != null)
            {
                _rb.AddExplosionForce(force, transform.position, radius);
            }
        }

        // Remove granade
        Destroy(gameObject);
    }
Exemple #8
0
    void OnTriggerEnter(Collider colInfo)
    {
        if (!GameManager.endGame)
        {
            if (colInfo.CompareTag("Player"))
            {
                Destructible destructible = (Destructible)colInfo.GetComponent("Destructible");
                destructible.Destroy();
            }

            GameManager.endGame = true;
            gameManager.LoadNextLevel(GameManager.currentLevel, 2.0f);
        }
    }
    void OnCollisionEnter(Collision col)
    {
        if (col.gameObject.name == "Player")
        {
            PlayerCollision coll = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerCollision>();
            if (coll.destr != true)
            {
                Instantiate(destroyedVersion, transform.position, transform.rotation);
            }
            else
            {
                Instantiate(explosionEffect, transform.position, transform.rotation);

                //function that allows us to create a shpere that we want the objects to interact with
                //returns array
                Collider[] collidersToDestroy = Physics.OverlapSphere(transform.position, radius);
                //in the first loop we destroy and in the second we apply forces
                foreach (Collider nearbyObject in collidersToDestroy)
                {
                    //destroy in pieces
                    Destructible des = nearbyObject.GetComponent <Destructible>();
                    if (des != null)
                    {
                        des.Destroy();
                    }
                }

                Collider[] collidersToMove = Physics.OverlapSphere(transform.position, radius);

                foreach (Collider nearbyObject in collidersToMove)
                {
                    Rigidbody rb = nearbyObject.GetComponent <Rigidbody>();
                    if (rb != null)
                    {
                        //built in unity function
                        rb.AddExplosionForce(force, transform.position, radius);
                    }
                }
            }

            Instantiate(destroyedVersion, transform.position, transform.rotation);
            // Remove the current object
            Destroy(gameObject);
        }
    }
Exemple #10
0
    void Shoot()
    {
        shootAudio.Play();

        currentAmmo--;

        gunFlash.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);
            }

            if (_hit.rigidbody != null)
            {
                _hit.rigidbody.AddForce(-_hit.normal * damage * impactForceConstant);
            }

            Destructible _destructibleObject = _hit.transform.GetComponent <Destructible>();
            if (_destructibleObject != null)
            {
                GameObject _go = _destructibleObject.Destroy();
                Destroy(_go, 15f);
                Rigidbody _rb = _go.GetComponent <Rigidbody>();
                if (_rb != null)
                {
                    _rb.AddExplosionForce(1f, transform.position, 5f);
                }
            }

            GameObject effect = Instantiate(impactEffect, _hit.point, Quaternion.LookRotation(_hit.normal));
            Destroy(effect, 1f);
        }
    }