Skip to content

Instantly share code, notes, and snippets.

@snowman647
Created May 7, 2023 15:32
Show Gist options
  • Save snowman647/1cbcc7acc48ff88a9021f0bee1819b76 to your computer and use it in GitHub Desktop.
Save snowman647/1cbcc7acc48ff88a9021f0bee1819b76 to your computer and use it in GitHub Desktop.
In-Game Wiki for Unity game using TextMesh Pro
// Code from my game about software development https://devmanager.carrd.co
//
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());
}
}
}
@snowman647
Copy link
Author

Code from my game about software development

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment