DEV Community

Cover image for In-Game Wiki in Unity in 15 min
Mike Krop
Mike Krop

Posted on • Updated on • Originally published at mitrapunk.com

In-Game Wiki in Unity in 15 min

This solution is ideal if you need a simple way to create a wiki in your game.

Solution is based on TextMesh Pro component.

The game itself is in active development, you can subscribe for updates about what does it mean to be manager

public class WikiUI : MonoBehaviour, IPointerClickHandler
{
    public TextMeshProUGUI text;

    public void OnenWikiAbout(string page)
    {
        text.text = "<line-height=125%>";

        if (page == "negotiations")
        {
            text.text += "Negotiations<br>Negotiations start when there are several opinions on the next steps. During negotiations, you and your colleagues communicate about which course to take.";
        }
        else if (page == "homepage")
        {
            text.text += "Wiki Index:<br><link=negotiations><u>Read about negotiations</u></link>";
        }
        else
        {
            text.text = "404<br>";
        }

        text.text += "<br><link=homepage><u>Go Home</u></link>";
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        // camera is null only if you use Screen Space Overlay, otherwise add camera reference
        int linkIndex = TMP_TextUtilities.FindIntersectingLink(text, eventData.position, null);

        if (linkIndex != -1)
        {
            TMP_LinkInfo linkInfo = text.textInfo.linkInfo[linkIndex];
            OnenWikiAbout(linkInfo.GetLinkID());
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)