Highlighting usable objects

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
mandi
Posts: 77
Joined: Wed Sep 16, 2015 4:05 am

Highlighting usable objects

Post by mandi »

Hello Tony,
I want to highlight any usable object by default, so that my player knows which objects to interact with. I created a component which, depending on enum, can be set as OnEnable or according to distance. Now, how to automatically bind that highlighting component with each object that has Usable? I know I can iterate over each object, but that's ineffective. I can modify Usable component, but any changes would be lost in case of DS update. Is there a way to extend Usable? A partial class somewhere?
Best!
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Highlighting usable objects

Post by Tony Li »

Hi Artur,

You can create a subclass of Usable and add this to your GameObjects instead of Usable. The only method that's not currently overridable is Start. I just made the Start method virtual. This will be in the next release. So if you need to override Start, please feel free to change Usable's Start method to virtual:

Code: Select all

public virtual void Start() {
and then call the base method in your subclass. For example:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class UsableExtended : Usable {

    public enum Mode { OnEnable, ByDistance}
    public Mode mode;
    
    public override void Start() {
        base.Start();
        // Your code here to do extra work in Start.
    }
    
    public void OnEnable() {
        if (mode == Mode.OnEnable) Highlight(1);
    }
    
    public void Update() {
        if (mode == Mode.ByDistance) Highlight(distanceFromPlayer);
    }
    
    public void Highlight(float intensity) {
        ...
    }
}
mandi
Posts: 77
Joined: Wed Sep 16, 2015 4:05 am

Re: Highlighting usable objects

Post by mandi »

Tony,
thank you very much!
Best!
Post Reply