Exemplo n.º 1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.rigidbody == null)
        {
            return;
        }

        Vector2 contactPoint    = collision.contacts[0].point;
        Vector3 contactPosition = new Vector3(contactPoint.x, contactPoint.y, -0.5f);

        if (collision.rigidbody.GetComponent <EnemyCar>() != null)
        {
            collision.rigidbody.GetComponent <EnemyCar>().PlayHitSound();

            if (!invulnerable)
            {
                GameManager.Instance.TakeHit();
                StartCoroutine("MakeInvulnerable");
            }


            if (impactParticleEffect != null)
            {
                impactParticleEffect.transform.position = contactPosition;
                impactParticleEffect.Play();
                cameraShake.TimedShake(0.5f);
            }
        }
        else if (collision.rigidbody.GetComponent <Dirt>() != null)
        {
            collision.collider.isTrigger = true;
            if (insideDirt == 0)
            {
                wiperManager.Dirty();
                particleManager.EnterDirt(contactPosition);
            }
            insideDirt++;
        }
    }