Sending OnUse messages from other objects.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
rykaan
Posts: 75
Joined: Tue Feb 11, 2020 6:22 am

Sending OnUse messages from other objects.

Post by rykaan »

Hi Tony,

Is it possible to send a message from the player to an object to trigger Dialogue System Triggers (for example) just from script? Or does it basically require a Selector to function correctly? I built my own raycast interaction scripts for my characters and I've been triggering OnUse messages on the objects hit rather than sending OnUse messages directly. This was fine until recently I realised that the accepted Tags and GameObjects don't function since they are effectively triggering themselves ¬_¬. The below code is what I expected to send the message across:

Code: Select all

hit = (Physics2D.Raycast(transform.position - new Vector3(0, 0.3f, 0),
                CharacterFacingMethods.DirectionFromAngle(0f, npcBase.facing), 1f, layerMask.value));
        if (hit != false)
        {
            SendMessage("OnUse", hit.transform);
Since "SendMessage("OnUse", transform);" correctly sends messages to itself, I was surprised this didn't work.

I know I've gone about this project in a weird way, but I have two simultaneously controlled main characters (like Brothers: A Tale of Two Sons), so I've been having to adapt quite a few things that would normally be fairly simple, but become a lot more complicated when there's a second main character running around. I figured fairly early on that the selector system may cause problems when both characters are looking at different things, so I tried going about it in a different way.

I assume I'm missing something fairly simple again.

Cheers,
Rob
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Sending OnUse messages from other objects.

Post by Tony Li »

Hi,

Sure, you can call/send OnUse on your own. The Selector and ProximitySelector components were originally just example scripts that demonstrated how you could write a script to call OnUse.

Try something like this:

Code: Select all

hit.collider.SendMessage("OnUse", this.transform);
This sends the message to hit.collider.

Alternatively, you could look into using ProximitySelector. Add a separate ProximitySelector to each PC. Enable the one on the PC that the player is currently controller, and disable the other one.
User avatar
rykaan
Posts: 75
Joined: Tue Feb 11, 2020 6:22 am

Re: Sending OnUse messages from other objects.

Post by rykaan »

Thankyou so much!

I do now have a bunch of stuff to rewrite, but this should make things flow a lot better.

Cheers!

Rob
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Sending OnUse messages from other objects.

Post by Tony Li »

Glad to help! :-)
Post Reply