Page 1 of 1

Call a Custom Method with Usable's OnUse()

Posted: Mon Dec 05, 2022 5:17 pm
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!

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

Posted: Mon Dec 05, 2022 6:53 pm
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.