Пример #1
0
    public void SpawnText(Vector3 position, string text, Color color)
    {
        FadingText ft = Instantiate(ftPrefab);

        ft.SetText(text);
        ft.SetColor(color);
        ft.transform.position = position;
        ft.transform.SetParent(transform);
    }
Пример #2
0
            /// <summary>
            /// Creates fading text effect. (Requires screen overlay canvas)
            /// </summary>
            /// <param name="pos"> The world space position of object. </param>
            /// <param name="text"> The text component of effect. </param>
            /// <param name="clr"> The color of text. </param>
            public void CreateFadingText(Vector2 pos, string text, Color clr)
            {
                // Create fading text and set its position from world space to screen space.
                GameObject tmp = Instantiate(fadingText) as GameObject;

                tmp.transform.SetParent(worldSpaceCanvas.transform, false);
                Vector3 uiPos = Camera.main.WorldToScreenPoint(pos);

                tmp.transform.position = uiPos;

                // Setup text properties.
                FadingText      ft    = tmp.GetComponent <FadingText>();
                TextMeshProUGUI tMesh = tmp.GetComponent <TextMeshProUGUI>();

                ft.SetText(tMesh, text);
                ft.SetColor(tMesh, clr);
            }