Example #1
0
    private bool SetupDestination()
    {
        if (stateMachine.currentWantedProduct == StockTypes.None)
        {
            // Decide on a random product to get
            stateMachine.currentWantedProduct = EssentialFunctions.GetRandomFromArray(stateMachine.mapManager.GetStockTypesAvailable());

            // Grab random shelf component on map with wanted product
            shelf = stateMachine.mapManager.GetRandomShelvingUnit(stateMachine.currentWantedProduct);
        }
        else if (stateMachine.taskDestination)
        {
            // Get shelf container if task destination exists already
            shelf = stateMachine.taskDestination.GetComponent <ShelfContainer>();
        }

        // Check if shelf exists
        if (!shelf)
        {
            return(false);
        }

        // Get shelf transform
        stateMachine.taskDestination = shelf.transform;

        // Get pickup position
        stateMachine.taskDestinationPosition = shelf.GetPickupPositions().Length == 1
            ? shelf.GetPickupPositions()[0]
            : EssentialFunctions.GetRandomFromArray(shelf.GetPickupPositions());

        return(true);
    }
Example #2
0
    public void UpdateState()
    {
        if (decided)
        {
            // Change state to walk state
            ToWalkToPositionState();
        }

        // Get random shelf wanted
        ShelfContainer selectedShelf = GetShelfDestination();

        stateMachine.taskDestination = selectedShelf.transform;

        Vector3[] pickupPositions = selectedShelf.GetPickupPositions();

        // Set AI destination to selected shelf
        stateMachine.taskDestinationPosition = pickupPositions[Random.Range(0, pickupPositions.Length - 1)];

        decided = true;
    }