playMaker

Author Topic: Adding functionality to specific words within a passage of text  (Read 1419 times)

BadgerFarmer

  • Playmaker Newbie
  • *
  • Posts: 11
Hi,

I'm looking for a way to make specific words in a passage of text interactable. From what I understand, this would be possible in C# using <link="ID>word</link> and writing a script that references the ID. But since I don't know C#, is there a way of achieving the same or similar in Playmaker?

I want to create a system where you click and hold on certain highlighted words, and that makes a copy of the word appear (as a separate button or TMP object) that you can drag and drop into another part of the screen.

Thanks for any advice.

BadgerFarmer

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Adding functionality to specific words within a passage of text
« Reply #1 on: July 25, 2023, 11:35:37 AM »
Apologies for the bump - I really can't find anything on this.

Is there no way to reference the rich text <link> tag in Playmaker to add functionality to individual words in a passage of text?

elvis75k

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 97
    • nRender
Re: Adding functionality to specific words within a passage of text
« Reply #2 on: July 31, 2023, 08:44:12 AM »
You can achieve this with TMPro.

"take the eyeglasses and <link="look"><b>look</b></link> around to find something, then step back and <link="quit"><b>quit</b></link>"

use this script on an TMPro object, then use some PlayMaker logic to read the ID with get property.

Code: [Select]
// from https://forum.unity.com/threads/clickable-link-within-a-text.910226/
// post #17 with some tweaks for the word, you can use get property on PM to get the clicked word...

using UnityEngine;
using TMPro;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;

[RequireComponent(typeof(TMP_Text))]
public class LinkOpener : MonoBehaviour, IPointerClickHandler
{
    private TMP_Text m_textMeshPro;
    public Camera MyCamera;
    public string LinkedWord;
    void Start()
    {
        m_textMeshPro = GetComponent<TMP_Text>();
    }
    public void OnPointerClick(PointerEventData eventData)
    {

        int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_textMeshPro, new Vector3(Mouse.current.position.x.ReadValue(), Mouse.current.position.y.ReadValue(), 0), MyCamera);
        if (linkIndex != -1)
        {
            TMP_LinkInfo linkInfo = m_textMeshPro.textInfo.linkInfo[linkIndex];
            //Application.OpenURL(linkInfo.GetLinkID());
            //Debug.Log("word is: " + linkInfo);
            Debug.Log(linkInfo.GetLinkID());
            LinkedWord = linkInfo.GetLinkID();
        }
    }

}
« Last Edit: July 31, 2023, 10:21:57 AM by elvis75k »

elvis75k

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 97
    • nRender
Re: Adding functionality to specific words within a passage of text
« Reply #3 on: August 01, 2023, 05:18:22 AM »
Action for playmaker; use the action after a mouse down. event, and store your string.

« Last Edit: August 01, 2023, 05:23:00 AM by elvis75k »

BadgerFarmer

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Adding functionality to specific words within a passage of text
« Reply #4 on: August 04, 2023, 12:25:57 AM »
Great. Thanks. I'll give it a try.