Esempio n. 1
0
    void FixedUpdate()
    {
        if (gameObject.tag != "Pumping")
        {
            return;
        }
        if ((TouchUp && TouchDown) || (TouchLeft && TouchRight))
        {
            rigidbody2D.MovePosition(lastFixedUpdatePosition);
            FillerScript.Stop(true);
            return;
        }

        float radius = gameObject.GetComponent <SpriteRenderer>().bounds.extents.x,
              xPos   = rigidbody2D.position.x,
              yPos   = rigidbody2D.position.y;

        float ToMoveUp    = yPos - (radius - (LeftUpCorner.y - yPos)),
              ToMoveDown  = yPos + (radius - (yPos - RightDownCorner.y)),
              ToMoveLeft  = xPos + (radius - (xPos - LeftUpCorner.x)),
              ToMoveRight = xPos - (radius - (RightDownCorner.x - xPos));

        Vector2 ToMoveVec = new Vector2(xPos, yPos);

        if (TouchUp)
        {
            ToMoveVec.y = ToMoveUp;
        }
        else if (TouchDown)
        {
            ToMoveVec.y = ToMoveDown;
        }
        if (TouchLeft)
        {
            ToMoveVec.x = ToMoveLeft;
        }
        else if (TouchRight)
        {
            ToMoveVec.x = ToMoveRight;
        }

        rigidbody2D.MovePosition(ToMoveVec);

        while (gameObject.GetComponent <SpriteRenderer>().bounds.extents.x -
               myBallFiller.GetComponent <SpriteRenderer>().bounds.extents.x > 0.2f)
        {
            myBallFiller.transform.localScale =
                myBallFiller.transform.localScale + new Vector3(0.001f, 0.001f, 0f);
        }

        lastFixedUpdatePosition = rigidbody2D.position;
    }