Is there a better way to highlight NPCs?
Posted: Sun Jun 24, 2018 11:38 am
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:
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!
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;
}
}
Thanks!