Esempio n. 1
0
 void OnTriggerEnter(Collider other)
 {
     //if collided with a player then apply the obstructions negatives to resources to the players inventory
     if (other.gameObject.CompareTag("Player1"))
     {
         GameObject    Player1         = GameObject.Find("Player1");
         ShipInventory InventoryScript = Player1.GetComponent <ShipInventory>();
         int           iGold           = InventoryScript.GetGold();
         int           iFood           = InventoryScript.GetFood();
         int           iCrew           = InventoryScript.GetCrew();
         iGold -= Random.Range(iMinGoldDamage, iMaxGoldDamage);
         //if there isnt enough gold, then set it to 0
         if (iGold < 0)
         {
             iGold = 0;
         }
         InventoryScript.SetGold(iGold);
         iFood -= Random.Range(iMinFoodDamage, iMaxFoodDamage);
         //if there isnt enough food, then set it to 0
         if (iFood < 0)
         {
             iFood = 0;
         }
         InventoryScript.SetFood(iFood);
         iCrew -= Random.Range(iMinCrewDamage, iMaxCrewDamage);
         //if there isnt enough crew, then set it to 0
         if (iCrew < 0)
         {
             iCrew = 0;
         }
         InventoryScript.SetCrew(iCrew);
     }
 }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (!GameEnd)
        {
            iFrames--;
        }

        while (iFrames > 1800)
        {
            iFrames  -= 1800;
            iMinutes += 1;
        }

        if (iFrames == 0 && iMinutes != 0)
        {
            iMinutes  -= 1;
            ShipParent = GameObject.FindGameObjectWithTag("Player1");
            ShipInventory ShipScript = ShipParent.GetComponent <ShipInventory>();
            int           iFood      = ShipScript.GetFood();
            int           iCrew      = ShipScript.GetCrew();
            if (iFood == 0)
            {
                Debug.Log("Half of crew: " + iCrew / 2);
                if ((iCrew / 2) < 1)
                {
                    iCrew--;
                }
                else
                {
                    iCrew = (iCrew / 2);
                }
                ShipScript.SetCrew(iCrew);
            }
            else
            {
                iFood -= iCrew;
                ShipParent.GetComponent <ShipInventory>().SetFood(iFood);
            }
            iFrames += 1800;
        }
        else if (iFrames == 600 || iFrames == 1200)
        {
            ShipParent = GameObject.FindGameObjectWithTag("Player1");
            ShipInventory ShipScript = ShipParent.GetComponent <ShipInventory>();
            int           iFood      = ShipScript.GetFood();
            int           iCrew      = ShipScript.GetCrew();

            if (iFood < iCrew)
            {
                iCrew -= (iCrew - iFood);
            }
            if (iFood == 0)
            {
                Debug.Log("Half of crew: " + iCrew / 2);
                if ((iCrew / 2) < 1)
                {
                    iCrew--;
                }
                else
                {
                    iCrew = (iCrew / 2);
                }
                ShipScript.SetCrew(iCrew);
            }
            else
            {
                iFood -= iCrew;
                ShipScript.SetFood(iFood);
            }
        }
        counterText.text = iMinutes + " : ";
        if (iFrames < 300)
        {
            counterText.text += "0" + iFrames / 30;
        }
        else
        {
            counterText.text += iFrames / 30;
        }
        if (iFrames <= 0 && iMinutes <= 0)
        {
            GC       = GameObject.FindGameObjectWithTag("GameControl");
            GCScript = GC.GetComponent <GameControl>();
            GCScript.SetGold(GameObject.FindGameObjectWithTag("Player1").GetComponent <ShipInventory>().GetGold());
            GCScript.SetEnding(2);
            SceneManager.LoadScene("Ending");
            GameEnd = true;
        }

        /*while (seconds > 0 && minutes > 0)
         * {
         *  minutes = (float)(0 - (Time.time / 60f));
         *  seconds = (float)(10 - (Time.time % 60f));
         *  counterText.text = minutes.ToString("00") + ":" + seconds.ToString("00");
         * }*/


        //if (minutes <= 0)
        //{
        //    if (seconds <= 1)
        //    {
        //        Application.Quit();
        //        //Debug.Log("Exit");
        //    }
        //}
    }