Beispiel #1
0
    void Update()
    {
        var firstPosition = first.GetPosition();
        var dir           = (second.GetPosition() - firstPosition) / 2;

        transform.position = firstPosition + dir;

        var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 90;

        transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);


        var maxWidth = MaxWidth;
        var minWidth = MinWidth;

        if (isRectFirst)
        {
            var rect = firstRect.rect;
            maxWidth = Mathf.Min(rect.width, rect.height) / 2.5f;
            minWidth = maxWidth - 0.1f;
        }
        var length = dir.magnitude * 2 - 1f / 3;
        var width  = Mathf.Lerp(maxWidth, minWidth, length / MaxLength);

        _rectTransform.sizeDelta = new Vector2(width, length);
    }
Beispiel #2
0
    public Vector2 GetTarget(IBindable self)
    {
        if (First != self && Second != self)
        {
            throw new Exception("Trying to get target for object that is not part of the bind");
        }
        Vector2 target;
        var     firstPos  = First.GetPosition();
        var     secondPos = Second.GetPosition();
        var     selfPos   = self.GetPosition();

        if (First == self)
        {
            target = secondPos - Offset;
        }
        else
        {
            target = firstPos + Offset;
        }
        return(target);
    }