Call a Custom Method with Usable's OnUse()

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
mclane
Posts: 1
Joined: Sun Dec 04, 2022 2:36 pm

Call a Custom Method with Usable's OnUse()

Post by mclane »

Hi Tony, thank you so much for this great asset. I am seeing if there is a way to call a method in a c# script I wrote through the Usable component's OnUse()?

For example, if my NPC has a "LookAtPlayer" function that rotates him to the player, how can I call this either through the component, or in code when the Useable component is used?

thanks!
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Call a Custom Method with Usable's OnUse()

Post by Tony Li »

Hi,

You can do either. You can add an OnUse(Transform) method to a script on the NPC:

Code: Select all

void OnUse(Transform player)
{
    transform.LookAt(player);
}
Or hook up a method to the OnUse() UnityEvent.

Or, if this is a conversation, use the LookAt() sequencer command or something similar in the conversation.
Post Reply