GraesonB/ChatGPT-Wrapper-For-Unity

Don't understand step 5

Closed this issue · 2 comments

Inexperienced Unity/UnityEvent user having trouble with step 5. Any guidance on waht it looks like to create a UnityStringEvent that invokes "SendToChatGPT" would be very helpful.

Hi there :-)

I'll try and explain this with my UI example.

In the UI there is a text box where a user can type a message, and a send button.

With Unity Events, there is always an Invoker (the send button) and a listener (ChatGPTConversation class). When the send button is pressed, it invokes the event, and anything listening to that event will be notified.

Since it is a UnityStringEvent (just a quick class I made that inherits from UnityEvent), the event ALSO passes a string to all listeners (the string comes from the text box).

So what you need to do is figure out how you want to get your string from the user, then declare a UnityStringEvent on a class that can get that string, and use yourUnityStringEvent.Invoke(yourString) somewhere. You'll see a little UnityEvent GUI element show up in your inspector inside the class where the event is declared. You can subscribe any methods that take a string inside the inspector by dragging the gameObject onto it and selecting a component and method from the drop-down.

Quick note, you might have to put #using ChatGPTWrapper; where you're declaring the event.

I hope this helps your understanding, if not it's all good. I'd recommend looking for resources on UnityEvents on YouTube. I'll eventually make a guide once I find some time

Brilliant, thank you so much