Sending OnUse messages from other objects.
Posted: Thu Jun 11, 2020 12:59 pm
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:
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
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);
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