Exemplo n.º 1
0
    void Unloading()
    {
        if (unloadingTimer <= Time.time)
        {
            // If there is space on the landing pad, place our cargo.
            if (landingPad.GetComponent <Node>().IsSpaceInCargo() == true)
            {
                // Reset the timer.
                unloadingTimer = Time.time + timeToUnload;

                // Create our cargo at an adjusted position
                Vector3 adjustedPosition = landingPad.transform.position;
                adjustedPosition.y += 1.0f;
                GameObject newCargo = Instantiate(cargoPrefab, adjustedPosition, Quaternion.identity);

                // Create a job.
                landingPad.GetComponent <Node>().CreateJob(newCargo);

                // Reduce the number of cargo on our ship.
                numberOfCargo += -1;

                // If we have fully unloaded, we leave.
                if (numberOfCargo <= 0)
                {
                    // Change our state
                    state = ShipState.Moving;

                    // Set a spawn position randomly in the air.
                    targetLocation = new Vector3(Random.Range(-150.0f, 150.0f),
                                                 Random.Range(100.0f, 150.0f),
                                                 Random.Range(-150.0f, 150.0f));

                    //Set ourselves to leaving.
                    leaving = true;

                    //Tell Air Traffic Control we are going and send them the code.
                    controller.Leaving(returnCode);
                }
            }
        }
    }