void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Wall" && bouncing < maxBouncing)
        {
            ContactPoint cp = collision.contacts[0];
            //rigidbody.velocity = Vector3.Reflect(rigidbody.velocity,collision.collider.transform.position.normalized);
            rigidbody.velocity = Vector3.Reflect(rigidbody.velocity, cp.normal) * 2;
            bouncing++;
        }
        else
        {
            if (collision.gameObject.GetComponent <CarStatus>() != null)
            {
                CarStatus car = collision.gameObject.GetComponent <CarStatus>();
                car.infligerDegat(damage);
            }

            GameObject            prefabExplosion = Resources.Load("Explosion") as GameObject;
            ExplosionPhysicsForce epf             = prefabExplosion.GetComponent <ExplosionPhysicsForce>();
            epf.explosionForce = 1;
            prefabExplosion.transform.position = this.transform.position;
            GameObject explosion = Instantiate(prefabExplosion) as GameObject;

            GameObject.Destroy(this.gameObject);
            GameObject.Destroy(explosion, 3);
        }
    }
    void Explosion()
    {
        GameObject            prefabExplosion = Resources.Load("Explosion") as GameObject;
        ExplosionPhysicsForce epf             = prefabExplosion.GetComponent <ExplosionPhysicsForce>();

        epf.explosionForce = 3;
        prefabExplosion.transform.position = this.transform.position;
        GameObject explosion = Instantiate(prefabExplosion) as GameObject;

        GameObject.Destroy(explosion, 3);
    }
Exemple #3
0
    // Entre dans cette fonction lorsqu il y a une collision
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.GetComponent <CarStatus>())
        {
            CarStatus car = collision.gameObject.GetComponent <CarStatus>();
            if (explode)
            {
                GameObject            prefabExplosion = Resources.Load("Explosion") as GameObject;
                ExplosionPhysicsForce epf             = prefabExplosion.GetComponent <ExplosionPhysicsForce>();
                epf.explosionForce     = explosionForce;
                car.transform.position = this.transform.position;
                GameObject explosion = Instantiate(prefabExplosion) as GameObject;
                GameObject.Destroy(explosion, 3);
            }
            if (destructible)
            {
                GameObject.Destroy(this.gameObject);
            }

            car.infligerDegat(damage);
        }
    }