I’m having a few issues with applying my typescript code on the onlick unity function to open the link when the unity object is clicked. How should i tackle this
by user 841751666960760944
I’m having a few issues with applying my typescript code on the onlick unity function to open the link when the unity object is clicked. How should i tackle this
by user 841751666960760944
Hello there – I’m an AI powered assistant that might be able to help you with your question. Would you like me to try helping you?
How it works:
Reply to the messages of the bot that end with a thread_id
to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.
Help requested: please wait a moment…
Here is what I found for you Discord
Hello Abdullah, implementing an onclick function to open a link in Unity using the Needle Engine can be done by using the OpenURL
component. Here’s the code structure based on what is documented:
import { OpenURL, OpenURLMode, IPointerClickHandler, PointerEventData } from '@needle-tools/engine';
import { Behaviour } from '@needle-tools/engine';
export class MyClickableObject extends Behaviour implements IPointerClickHandler {
@serializable()
url: string;
// Optional: Choose how to open the URL.
// This is not required and will default to opening in a new tab.
mode: OpenURLMode = OpenURLMode.NewTab;
start(): void {
// Ensure the component is clickable.
// If you already have a clickable component on the GameObject, this can be omitted.
this.getComponent(OpenURL).clickable = true;
}
onPointerClick(args: PointerEventData): void {
// Open the URL that you have set in the url field when the GameObject is clicked.
const openUrlComponent = this.getComponent(OpenURL);
openUrlComponent.url = this.url;
openUrlComponent.mode = this.mode;
openUrlComponent.open();
}
}
Please make sure you have an OpenURL
component attached to your GameObject. Remember to replace "@needle-tools/engine"
imports with the correct package path that you’re using. Ensure the GameObject is set as clickable and the URL is properly defined to make sure the click triggers the link opening (see the documentation).
1 messages left GPT 4
thread_DqGc67eVTmNpmGbxGekY8WrA
Thanks for your feedback!
yooo this is insane
by user 841751666960760944
big ups to the needle engine people who made this
by user 841751666960760944
You dont need to write your own component for this: just add the OpenURL component to your object