Пример #1
0
    /// <summary>
    /// Creates a new <see cref="Resource"/> iff
    /// the current <see cref="resource"/> is null and
    /// the current <see cref="Time.time"/> is greater
    /// or equal to the <see cref="timeToSpawn"/>. Afterwards
    /// it is handed to the <see cref="output"/>.
    /// </summary>
    void Update()
    {
        if (resource == null && Time.time > timeToSpawn)
        {
            resource = (Resource)Instantiate(resourceTemplate, transform.position, transform.rotation);
        }

        if (resource != null && output != null && output.Accepts(resource))
        {
            output.Take(resource);
            resource    = null;
            timeToSpawn = Time.time + cooldown;
        }
    }
Пример #2
0
    /// <summary>
    /// Iff cargo is not null, its progress is
    /// computed with regard to the given <see cref="speed"/>.
    /// Iff the <see cref="progress"/> is greater or equal
    /// one the cargo will be handed to the registered
    /// <see cref="output"/>. Iff there is no <see cref="output"/>
    /// or it does not accept the cargo nothing happens until
    /// this state of affair changes. <see cref="SetPosition"/>
    /// is called afterwards.
    /// </summary>
    public void Update()
    {
        if (cargo == null)
        {
            return;
        }

        progress += speed * Time.deltaTime;
        if (progress >= 1)
        {
            progress = 1;
            if (output != null && output.Accepts(cargo))
            {
                output.Take(cargo);
                cargo    = null;
                progress = 0;
                return;
            }
        }
        SetPosition();
    }