Ejemplo n.º 1
0
    public void Update()
    {
        if (state == states.REACHING)
        {
            float progress = grabTimer.TimeElapsedSecs() / reachTime;
            float dist;

            if (progress >= 1f)             //if we've reached past
            {
                state = states.GRABBING;
                dist  = distance;
                grabTimer.Restart();
            }
            else if (progress > SLOW_THRESH)
            {
                float subProgress = (progress - SLOW_THRESH) / (1f - SLOW_THRESH);
                dist = headMinimum + fastLegDist + mediLegDist + subProgress * slowLegDist;
            }
            else if (progress > MEDI_THRESH)
            {
                float subProgress = (progress - MEDI_THRESH) / (SLOW_THRESH - MEDI_THRESH); //how much of the medium speed leg has it travered?
                dist = headMinimum + fastLegDist + subProgress * mediLegDist;               //get actual distance
            }
            else
            {
                float subProgress = progress / MEDI_THRESH;               //how much of the fast leg has it traversed?
                dist = headMinimum + subProgress * fastLegDist;           //get actual distance from center to put the thing
            }
            PositionHead(dist);
        }
        else if (state == states.GRABBING)
        {
            if (grabTimer.TimeElapsedSecs() > GRAB_TIME)
            {
                grabTimer.Restart();
                RectTransform dropRT = (RectTransform)target.transform;
                target.transform.eulerAngles = new Vector3(0, 0, 0);
                target.transform.SetParent(head.transform, false);
                dropRT.anchoredPosition = new Vector2(0, 0);
                state = states.PULLING;
            }
        }
        else if (state == states.PULLING)
        {
            float progress = 1f - (grabTimer.TimeElapsedSecs() / reachTime);
            float dist;

            if (progress > SLOW_THRESH)
            {
                float subProgress = (progress - SLOW_THRESH) / (1f - SLOW_THRESH);
                dist = headMinimum + fastLegDist + mediLegDist + subProgress * slowLegDist;
            }
            else if (progress > MEDI_THRESH)
            {
                float subProgress = (progress - MEDI_THRESH) / (SLOW_THRESH - MEDI_THRESH); //how much of the medium speed leg has it travered?
                dist = headMinimum + fastLegDist + subProgress * mediLegDist;               //get actual distance
            }
            else if (progress > 0f)
            {
                float subProgress = progress / MEDI_THRESH;               //how much of the fast leg has it traversed?
                dist = headMinimum + subProgress * fastLegDist;           //get actual distance from center to put the thing
            }
            else
            {
                state = states.DONE;
                dist  = headMinimum;
            }
            PositionHead(dist);
        }
        else if (state == states.DONE)
        {
            Drop seized = target.GetComponent <Drop>();
            seized.AddPieceToInventory();
            Destroy(seized.gameObject);
            Destroy(gameObject);
        }
    }