Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        // look under the mouse for a tooltip source
        current = null;
        Vector2    pos = Input.mousePosition;
        GameObject go  = GetObjectUnderPos(pos);

        if (go)
        {
            // found an object...
            current = go.GetComponent <ITooltip>();
            if (current != null)
            {
                tooltipObject.SetActive(true);

                // we need this to force a recalculation of the text size to propagate up to the parent frame
                toolTipText.text = "";
                // set the text to the tooltip one
                toolTipText.text = current.GetTip();
                // poisiton at the mouse
                toolTipTransform.position = go.transform.position;
                // make it point inwards to the centre of the screen
                toolTipTransform.pivot = new Vector2(pos.x > Screen.width / 2 ? 1 : 0,
                                                     pos.y > Screen.height / 2 ? 1 : 0);
            }
        }


        // turn the tooltip on or off based on whether we have a thing under the mouse
        tooltipObject.SetActive(current != null);
    }