コード例 #1
0
    //add logic for collisions
    //check collision and call appropriate methods
    void OnCollisionEnter2D(Collision2D col)
    {
        switch (col.gameObject.tag)
        {
        case "EnemyBike":
            Instantiate(explosion, transform.position, new Quaternion(0, 0, 0, 0));
            sound.playExplosion();
            Destroy(gameObject);
            Destroy(col.gameObject);
            health.decrementHealth();
            break;

        case "Player":
            Instantiate(explosion, transform.position, new Quaternion(0, 0, 0, 0));
            sound.playExplosion();
            Destroy(gameObject);
            health.decrementHealth();
            break;

        //error handling
        default:
            Debug.Log("You shouldn't see this, check where this bullet went");
            break;
        }
    }