On Use command and Variables

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Danzer
Posts: 3
Joined: Wed Apr 21, 2021 5:49 am

On Use command and Variables

Post by Danzer »

I'm using the "On Use" command trigger to start a conversation with a 2D NPC but it doesn't work (it works with "On Start").

I'll explain the steps I made:
- I Imported the DialogueManager and created a DialogueDatabase and setted it as Reference database
- I Created my conversation
- I Created an NPC and a Player
- The Player has the selector component (I increased the distance for the selection just in case); the NPC has a Sprite Renderer, a Box collider set on "Is Trigger"; a Dialogue System Trigger set on "On Use" with the right Dialogue Database Reference and the Action to start the right conversation; and an Usable component (Max distance 30).

I have enabled the 2D Physics just in case, but doesn't change anything, I can't select the NPC to start the conversation, and the Selector does not display anything if the mouse position is on the NPC box collider.

Here the scene:

[removed]

I'm using Unity 2020 LTS, but I tried 2019 LTS with the same result.


Second question: Is it possible to read a variable from the database and change its value from a C# script like you do with the animator variables? Is there a tutorial or an example for this?

Thank you in advance for the help.
User avatar
Tony Li
Posts: 22161
Joined: Thu Jul 18, 2013 1:27 pm

Re: On Use command and Variables

Post by Tony Li »

Hi,

Open the Dialogue System's Welcome Window (menu item Tools > Pixel Crushers > Dialogue System > Welcome Window) and double-check that the USE_PHYSICS2D checkbox is still ticked.

Then inspect the player's Selector component and set "Run Raycasts" to "In 2D".
Danzer
Posts: 3
Joined: Wed Apr 21, 2021 5:49 am

Re: On Use command and Variables

Post by Danzer »

Use Physics2D was checked, the problem was the Run Raycasts set in 3D. Thanks for the help :D

About the variables? Is there a simple way to read and write the variables you create in the dialogue database with a C# script?
User avatar
Tony Li
Posts: 22161
Joined: Thu Jul 18, 2013 1:27 pm

Re: On Use command and Variables

Post by Tony Li »

Sorry, I forgot to answer that. Yes. Use DialogueLua.GetVariable() and SetVariable(). Example:

Code: Select all

int score = DialogueLua.GetVariable("Score").asInt;
if (score > 100) DialogueLua.SetVariable("Won", true);
Post Reply