예제 #1
0
    private void OnTriggerEnter(Collider other)
    {
        //Find all the tanks in the area around the shell and damage them.
        Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius, tankMask);
        //Having it to check them
        for (int i = 0; i < colliders.Length; i++)
        {
            //Check the rigid body of the object
            Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();
            //Has it found a rigid body
            if (!targetRigidbody)
            {
                continue;
            }
            // TODO: Add force to push tank
            //targetRigidbody.AddExplosionForce(explosionForce, transform.position, explosionRadius);
            // TODO: Begin to apply damage to the tank player script (in the tutorial has a script by itself for the health of the tank)
            TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>();
            //if(!targetHealth)
            //continue;
            // TODO: Create damage by seeing how far it is from the explosion.
            //float damage = CalculateDamage (targetRigidbody.position);
            //Updates the amount of health left to the player.
            targetHealth.DamageAmount(10);

            Debug.Log("hit has been his");
        }
        // TODO: Spawn the particle affect of the explosion
        explosionParticles.transform.parent = null;
        explosionParticles.Play();
        Destroy(explosionParticles.gameObject, explosionParticles.main.duration);
        // TODO: Play the audio file for the explosion.
        explosionAudio.Play();
    }