Interacting with C# scripts

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Ingot
Posts: 8
Joined: Sun Feb 21, 2016 3:29 pm

Interacting with C# scripts

Post by Ingot »

I am trying to get the Dialogue System to call a function on a game object that is used as my cursor manager.
I attached a DialogueSystemTrigger script to the player and set it to OnUse. The problem is that I can't select
the cursor manager as the game object to send the message to in the Send Messages area because the component
will not allow that. If I include the DialogueSystemTrigger component on the cursor control object and call the
function from the Send Messages it works fine, but not from the player object. How can I get it to work?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Interacting with C# scripts

Post by Tony Li »

Hi,

I'm not sure I have a clear idea of what you're attempting. This is my understand so far:

1. You added a DialogueSystemTrigger to the player GameObject and set it to OnUse. This means the DialogueSystemTrigger will only fire if the player GameObject receives an OnUse message (and if the Condition is true).

2. In the DialogueSystemTrigger's Action > Send Messages section, you added an element and tried to assign the cursor manager GameObject to its Game Object field -- but the Inspector wouldn't let you assign it?

Would you please describe what you would ultimately like to happen and the actions the player and/or game would take to make it happen?
Ingot
Posts: 8
Joined: Sun Feb 21, 2016 3:29 pm

Re: Interacting with C# scripts

Post by Ingot »

Sure,

#1 is all true which explains my issue.

#2 is also all true which I believe #1 explains.

The overall synopsis is that I have a first person controller with a custom cursor and it is locked to the screen center using OnGUI.
When the player walks up to an NPC and clicks the activate button, the dialogue opens but the cursor is still locked to the center.
My ToggleCursorLocked method within CursorControl will handle that with a call.

Since the DialogueSystemTrigger will only fire from an object that is being used, having it fire from the player to call a function
on the cursor control object will not work. When I tried to add the cursor control game object to the send message elements
on the player object, it was blocked with circle and slash. Knowing these things now, when I add the DialogueSystemTrigger
component to the NPC, I am able to assign the cursor control object to the send message actions. This fixed my problem and
the cursor toggle works. Thank you for your prompt response.

Now, how do I call the same method from the "Goodbye" in the dialogue editor to re-lock the cursor?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Interacting with C# scripts

Post by Tony Li »

Hi,
Ingot wrote:Now, how do I call the same method from the "Goodbye" in the dialogue editor to re-lock the cursor?
You can use the SendMessage() sequencer command. For example, in your "Goodbye" dialogue entry node, set the Sequence field to:

Code: Select all

SendMessage(LockCursor)
This assumes that "Goodbye" is being spoken by the player, and that your custom cursor script on the player's GameObject has a method LockCursor(). If that's not the case, you may need to change the parameters a bit. (Details are in the link above.)

However, it sounds like the OnConversationStart and OnConversationEnd messages might be an easier way to do this. You could add these methods to your custom cursor script:

Code: Select all

void OnConversationStart(Transform otherParticipant) {
    UnlockCursor(); // Unlock the cursor during conversations.
}

void OnConversationEnd(Transform otherParticipant) {
    LockCursor(); // Lock the cursor again when the conversation is over.
}
This example code once again assumes your script has LockCursor() and UnlockCursor() methods.

Using this solution, you don't need a Dialogue System Trigger or special sequencer commands or any of that. It's all contained in your custom cursor script. When the player is involved in a conversation, the Dialogue System will call these methods automatically.
Ingot
Posts: 8
Joined: Sun Feb 21, 2016 3:29 pm

Re: Interacting with C# scripts

Post by Ingot »

Ok, thank you.. that approach worked great.
Post Reply