コード例 #1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        ResourceLogic rl = other.gameObject.GetComponent <ResourceLogic>();

        if (rl != null)
        {
            dr.AddResource(rl.drillResources);
            Destroy(other.gameObject);
        }
    }
コード例 #2
0
ファイル: ObjectRepairLogic.cs プロジェクト: TheCell/50.DEEP
    public DrillResources Repair(DrillResources playerResources)
    {
        DrillResources resourceReduction = new DrillResources();

        switch (typeOfResourceForRepair)
        {
        case ResourceType.Antrieb:
            int amountAntriebMissing = 100 - currentObjectResource.Antrieb;
            GetComponent <AudioSource>().Play();
            if (playerResources.Antrieb >= amountAntriebMissing)
            {
                // player has the amount or more in inventory. Reduce inventory
                currentObjectResource.Antrieb = 100;
                resourceReduction.Antrieb     = -amountAntriebMissing;
            }
            else
            {
                // player has less resource then needed. Only repairing the amount hold
                int stillAmountMissing = amountAntriebMissing - playerResources.Antrieb;
                resourceReduction.Antrieb     = -playerResources.Antrieb;
                currentObjectResource.Antrieb = 100 - stillAmountMissing;
            }
            break;

        case ResourceType.Baumaterial:
            //int amountBaumaterialMissing = 100 - currentObjectResource.Baumaterial;
            currentObjectResource.Baumaterial = 100;
            GetComponent <AudioSource>().Play();

            //if (playerResources.Antrieb >= amountBaumaterialMissing)
            //{
            //    // player has the amount or more in inventory. Reduce inventory
            //    currentObjectResource.Baumaterial = 100;
            //    resourceReduction.Baumaterial = -amountBaumaterialMissing;
            //}
            //else
            //{
            //    // player has less resource then needed. Only repairing the amount hold
            //    int stillAmountMissing = amountBaumaterialMissing - playerResources.Baumaterial;
            //    resourceReduction.Baumaterial = -playerResources.Baumaterial;
            //}
            break;

        case ResourceType.Wasser:
            int amountWasserMissing = 100 - currentObjectResource.Wasser;
            GetComponent <AudioSource>().Play();

            if (playerResources.Wasser >= amountWasserMissing)
            {
                // player has the amount or more in inventory. Reduce inventory
                currentObjectResource.Wasser = 100;
                resourceReduction.Wasser     = -amountWasserMissing;
            }
            else
            {
                // player has less resource then needed. Only repairing the amount hold
                int stillAmountMissing = amountWasserMissing - playerResources.Wasser;
                resourceReduction.Wasser     = -playerResources.Wasser;
                currentObjectResource.Wasser = 100 - stillAmountMissing;
            }
            break;
        }

        UpdateSprites();
        playerResources.AddResource(resourceReduction);
        Debug.Log(
            "Object ressources after"
            + "Antrieb " + currentObjectResource.Antrieb
            + " baumat " + currentObjectResource.Baumaterial
            + " wasser " + currentObjectResource.Wasser);
        return(playerResources);
    }