Forum rules - please read before posting.

Highlight part of an object which has multiple hotspots

Hi all,

I have an NPC that has multiple hotspots, each leading to separate interactions. I'm wondering if there's a way to highlight each specific part of my NPC game object to mirror the selection of the individual hotspot areas? Perhaps using the hotspot itself and referring to where it overlaps the NPC? Will I need to separate my NPC into component parts and have them made visible and highlighted?

I've managed to get the hotspot highlighting the entire NPC on mouse over but I'd like to pinpoint the hotspotted area itself if possible. Any ideas?

Comments

  • Welcome to the community, @afromcpie.

    Yes, the default highlighting effect works by brightening each material found on the Renderer component it's attached to. To rely on it, you'd need to have each body part you want to isolate be a different renderer.

    Alternatively, you could uncheck Auto-brighten materials when enabled? in the Highlight's Inspector so that it doesn't affect anything visually - but still keeps track itself of its own effect intensity. You could then rely on a custom script that reads the component's GetHighlightIntensity() value and applies it in some custom way.

  • edited July 2020

    Thanks Chris, I'm super new to coding so I think the custom script might be a little out of my reach.

    I've been researching masks. Do you think its possible, as a workaround, to have a circular shaped mask that darkens the surrounding scene (using some kind of semi transparent block of colour with a hole cut in), but leaves the area beneath (i.e. the gameobject) normal brightness. I'd need to have this mask only become active / visible when the user puts the mouse over the object.

  • edited July 2020

    You probably could, yes - by attaching an Animator to such a sprite and defining animations that control it's colour. You could then control the playback of these two animation by creating transitions that make use of a Bool parameter.

    It's still different to the default behaviour, though, so you'd still need to uncheck the field I mentioned above. But if you then check Call custom events?, you can use the event boxes that then appear to change the value of the Animator's Bool parameter.

    I'd recommend going with the script-method though - it just depends on how the character is set up. If you can give each independent part you want to affect its own material (even if it's just one SkinnedMeshRenderer), then you can attach the following script to each Highlight component to choose which renderer and material index it should affect:

    using UnityEngine;
    using AC;
    
    public class HighlightSingleMaterial : MonoBehaviour
    {
    
        private Highlight highlight;
        public Renderer _renderer;
        public int materialIndex;
        private Color originalColor;
    
        void Awake ()
        {
            highlight = GetComponent <Highlight>();
            originalColor = _renderer.materials[materialIndex].color;
        }
    
        void Update ()
        {
            float alpha = _renderer.materials[materialIndex].color.a;
            Color newColor = originalColor * highlight.GetHighlightIntensity ();
            newColor.a = alpha;
            _renderer.materials[materialIndex].color = newColor;
        }
    
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.