Exemplo n.º 1
0
    //Moves an object by an ammount, under time
    IEnumerator MoveHorizontalBy(Transform obj, float moveBy, float time, bool changeBackPackState)
    {
        //If changeing state is allowed, change to in transit state
        if (changeBackPackState)
        {
            backPackState = BackPackState.inTransit;
        }

        //Move the menu to the designated position under time
        float i    = 0.0f;
        float rate = 1.0f / time;

        Vector3 startPos = obj.localPosition;
        Vector3 endPos   = startPos;

        endPos.x += moveBy;

        while (i < 1.0)
        {
            i += Time.deltaTime * rate;
            obj.localPosition = Vector3.Lerp(startPos, endPos, i);
            yield return(0);
        }

        //If changing state is allowed, change to the right state
        if (changeBackPackState)
        {
            if (moveBy < 0)
            {
                backPackState = BackPackState.open;
            }
            else
            {
                backPackState = BackPackState.close;
            }
        }
    }
Exemplo n.º 2
0
    //Moves an object by an ammount, under time
    IEnumerator MoveHorizontalBy(Transform obj, float moveBy, float time, bool changeBackPackState)
    {
        //If changeing state is allowed, change to in transit state
        if (changeBackPackState)
            backPackState = BackPackState.inTransit;

        //Move the menu to the designated position under time
        float i = 0.0f;
        float rate = 1.0f / time;

        Vector3 startPos = obj.localPosition;
        Vector3 endPos = startPos;
        endPos.x += moveBy;

        while (i < 1.0)
        {
            i += Time.deltaTime * rate;
            obj.localPosition = Vector3.Lerp(startPos, endPos, i);
            yield return 0;
        }

        //If changing state is allowed, change to the right state
        if (changeBackPackState)
        {
            if (moveBy < 0)
                backPackState = BackPackState.open;
            else
                backPackState = BackPackState.close;
        }
    }