Ejemplo n.º 1
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.isTrigger || other.gameObject == parent)
        {
            return;
        }
        TankHealth _health = other.GetComponent <TankHealth>();

        _health?.Hit();
        gameObject.SetActive(false);
    }
Ejemplo n.º 2
0
    private void OnCollisionEnter(Collision collision)
    {
        bool hasHit = false;
        // ... and find their rigidbody.
        Rigidbody targetRigidbody = collision.gameObject.GetComponent <Rigidbody>();

        // If they don't have a rigidbody, go on to the next collider.
        if (targetRigidbody)
        {
            EnemyTankHealth targetHealth = targetRigidbody.GetComponent <EnemyTankHealth>();
            TankHealth      playerHealth = targetRigidbody.GetComponent <TankHealth>();
            // If there is no TankHealth script attached to the gameobject, go on to the next collider.
            if (targetHealth)
            {
                targetHealth.Hit();
                hasHit = true;
            }
            else if (playerHealth)
            {
                playerHealth.Hit();
                hasHit = true;
            }
        }

        if (hasHit || m_BouncesLeft <= 0 || collision.gameObject.CompareTag(m_ProjectileTag))
        {
            Explode();
        }
        else if (!hasHit && m_BouncesLeft > 0)
        {
            ContactPoint contact = collision.contacts[0];
            lastVelocity = Vector3.Reflect(lastVelocity, contact.normal);
            rb.velocity  = lastVelocity;
            rb.MoveRotation(Quaternion.LookRotation(lastVelocity));
            m_BouncesLeft--;
            OnRicochet();
        }
    }