コード例 #1
0
    public void CheckBeat(ColorType type)
    {
        if (layers.Count == 0 && !outliner.resetting && !outliner.gameObject.active)
        {
            particles.Play();
            ui.FirstMove();
            perfectItteration = true;
            failAudio.Play();
            NewItteration();
            return;
        }

        LayerObject closestObject = layers[0];
        float       distance      = Mathf.Infinity;
        int         index         = 0;
        int         closestIndex  = 0;

        foreach (LayerObject layer in layers)
        {
            if (Mathf.Abs(outliner.Scale - layer.layer.transform.localScale.x) < distance)
            {
                closestIndex  = index;
                closestObject = layer;
                distance      = Mathf.Abs(outliner.Scale - layer.layer.transform.localScale.x);
            }
            index++;
        }


        float precentage = distance / (1f / (float)layers.Count); // between 0 and 50

        if (precentage > precentageMarge || closestObject.inPulse || type != closestObject.layer.Type)
        {
            RemoveLayerAt(closestIndex);
        }
        else
        {
            if (layers.IndexOf(closestObject) != layers.Count - 1 || !perfectItteration)
            {
                closestObject.layer.Dance();
            }
            closestObject.inPulse = true;
        }
        outliner.Pulse();
    }