Page 1 of 1

Is there a better way to highlight NPCs?

Posted: Sun Jun 24, 2018 11:38 am
by rileypb
First off, wow! Dialogue System 2.x is an amazing upgrade from 1.x!

I'm wondering if there's a "better", more conventional way to do this. I'm trying to highlight NPCs when they are selected via ProximitySelector. Here's some code illustrating what I'm doing now:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;

public class HighlightSelectedUsable : MonoBehaviour {

private ProximitySelector selector;

// Use this for initialization
void Start () {
selector = GetComponent<ProximitySelector>();
selector.SelectedUsableObject += OnSelectedUsable;
selector.DeselectedUsableObject += OnDeselectedUsable;
}


void OnSelectedUsable(Usable usable) {
SpriteRenderer r = usable.gameObject.GetComponentInChildren<SpriteRenderer>();
r.color = Color.blue;
}

void OnDeselectedUsable(Usable usable)
{
SpriteRenderer r = usable.gameObject.GetComponentInChildren<SpriteRenderer>();
r.color = Color.white;
}

}
This works, but is there a way to do it without explicitly registering event delegates? The "On Selected Usable" setting in ProximitySelector doesn't seem to provide a way to determine what instance of Usable is currently selected, but I may be missing something.

Thanks!

Re: Is there a better way to highlight NPCs?

Posted: Sun Jun 24, 2018 2:23 pm
by Tony Li
Hi,

The "On Selected Usable ()" and "On Deselected Usable ()" events can pass the Usable to its event handlers. The target needs a method that accepts a Usable parameter. Select the method from the "Dynamic Usable" list:

Image

Although as a programmer I personally prefer to let a script hook things up automatically using event delegates rather than hooking them up visually in the editor. That's just my preference, though.