예제 #1
0
    // Fills the color container of the gun
    private void FillContainer(Pillar pillar)
    {
        // Fill container if it's not full
        if (containerFill < 1f)
        {
            if (!audioSource.isPlaying)
            {
                audioSource.Play();
            }

            // Extract from pillar
            Color c = pillar.Extract();

            // Add fill to container
            // WARNING: note that this is unrelated to pillar extraction, both values are changed separately
            containerFill = Mathf.Clamp(containerFill + GetExtractionAmt(), 0f, 1f);

            Debug.Log("Filling: " + containerFill * 100f + "%");             // TODO remove debugging code

            // If the color is empty (null) or different from the color currently being extracted, empty the container
            // and load a new color
            if (colorInContainer != c)
            {
                colorInContainer = c;
                containerFill    = 0;
            }
        }
        else
        {
            // If container is full and color is set
            if (colorInContainer != null && pillar.Color == colorInContainer)
            {
                // Set container color to pillar color (which was loaded into the variable earlier)
                Debug.Log("Done");                 // TODO remove debugging code
                pillar.Depleted = true;
                if (audioSource.isPlaying)
                {
                    audioSource.Stop();
                }
            }
        }

        UpdateContainer();
    }