示例#1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        string layer = LayerMask.LayerToName(other.gameObject.layer);

        switch (layer)
        {
        case "Projectile":
            break;

        case "Drops":
            Ammo ammo = other.GetComponent <Ammo>();
            ammo.Cleanup();
            break;

        case "Corpses":
            Enemy enemy = other.GetComponent <Enemy>();
            if (enemy.isDead)
            {
                enemy.Cleanup();
            }
            else
            {
                Debug.LogWarning($"Corpse isn't dead: {enemy.gameObject.name}");
            }
            break;

        case "Chunk":
        case "Background":
            other.transform.position += Vector3.right * chunkWidth * 2;
            break;

        default:
            Debug.LogWarning($"Scroller hit unknown object named {other.gameObject.name} on layer {layer}.");
            break;
        }
    }