Exemplo n.º 1
0
    void Update()
    {
        //Check if mine exist
        if (!doesMineExist)
        {
            if (_mine = GameObject.FindGameObjectWithTag("GoldCloud"))
            {
                doesMineExist = true;
                _mineCheck = _mine.GetComponent<GoldCloud>();
            }
        }

        if (doesMineExist && currentGold == 0)
            fsm.SetEvent(0);
        if (!doesMineExist)
            fsm.SetEvent(4);
        if (atMine)
            fsm.SetEvent(1);
        if (atBase)
            fsm.SetEvent(3);
        if (currentGold >= maxGold || (currentGold > 0 && _mine.tag == "EmptyCloud"))
            fsm.SetEvent(2);

        currentState = fsm.GetState();

        switch (fsm.GetState())
        {
            case 0:
                break;
            case 1:
                //Move to mine
                //nma.destination = _mine.transform.position;
                if (path.Count <= 0)
                {
                    path = pathMan.ChartRoute(transform.position, _mine.transform.position);
                }
                TravelPath();
                break;
            case 2:
                //Move to base
                //nma.destination = _base.transform.position;
                if (path.Count <= 0)
                {
                    path = pathMan.ChartRoute(transform.position, _base.transform.position);
                }
                TravelPath();
                break;
            case 3:
                //Get gold
                _mineCheck.goldAction--;
                currentGold++;
                break;
            case 4:
                //Deposit gold
                currentGold--;
                break;
        }
    }