示例#1
0
    /**
     * Sets position this balanced component should move to using weightmodifier.
     * The weight modifier is equal to the sibling BalanceComponent's weight minus this one's weight.
     * This means that a weight modifier of -1 would move this GameObject to the position where it should
     * be if it weighed 1 unit more than its sibling.
     */
    public void SetMoveTo(int weightModifier)
    {
        BalanceSplitter parent = transform.parent.GetComponent <BalanceSplitter>();

        Vector2 maxHeight = balanced + new Vector2(0, parent.GetMaxMotion());
        Vector2 minHeight = balanced - new Vector2(0, parent.GetMaxMotion());

        float t = (float)(weightModifier + parent.GetMaxWeightChildren()) / (2 * parent.GetMaxWeightChildren());   //Finds a value between [0,1] where 0 means the bottom position and 1 means the top

        moveFrom    = transform.localPosition;
        moveTo      = Vector2.Lerp(minHeight, maxHeight, t);
        timeElapsed = 0;
    }
示例#2
0
 void Awake()
 {
     splitter = transform.GetChild(0).GetComponent <BalanceSplitter>();
 }