Exemple #1
0
    // when an object enters this trigger
    void OnTriggerEnter2D(Collider2D other)
    {
        var            player = transform.parent;
        HealthAndLives health = player.GetComponent <HealthAndLives>();

        if (other.gameObject.CompareTag("enemy"))
        {
            // deduct health based on front (ram) or rear (rammed) collision
            if (gameObject.CompareTag("front"))
            {
                health.OnBumpTrigger(damageMinor);
                // do damage to enemy:
                if (other.gameObject.GetComponent <AICar> ().Bump())
                {
                    health.incrementKills();
                }
            }
            else
            {
                health.OnBumpTrigger(damageMajor);
            }
        }
        // collision with edge of track:
        if (other.gameObject.CompareTag("track"))
        {
            health.OnBumpTrigger(damageMajor);
        }
    }
Exemple #2
0
    // when missile hits something...
    void OnTriggerEnter2D(Collider2D other)
    {
        var            player = GameObject.Find("PlayerCar");
        HealthAndLives health = player.GetComponent <HealthAndLives> ();

        if (other.gameObject.CompareTag("enemy"))
        {
            other.gameObject.GetComponent <AICar> ().Kill();
            if (GetComponent <FireBullet> ().playerShot)
            {
                // got him!
                health.incrementKills();
            }
            Destroy(gameObject);
        }
        else if (other.gameObject.CompareTag("Player"))
        {
            // got me!
            health.Die();
            Destroy(gameObject);
        }
        else if (other.gameObject.CompareTag("track"))
        {
            // missed...
            Destroy(gameObject);
        }
    }