Forum rules - please read before posting.

Object Highlight Flashing - Strange results

Hello,

I'm trying to force an object to flash (highlight) when it's hit. The strange thing is I can achieve this via a script attached to the projectile which hits it, but, I can't do it if the detection is on the hotspot itself.

For instance, I have this script on a projectile;

private void OnTriggerEnter(Collider other)
    {
        //Try and grab the hotspot component of the object
        var hotspot = other.GetComponent<Hotspot>();

        //If it doesn't have a hotspot then return
        if (hotspot == null) return;

        //Flash the object (highlight)
        StartCoroutine("Flash"); 
    }

    IEnumerator Flash()
    {
        //Set to selected (makes object trigger highlight)
        hotspot .Select();

        //Wait
        yield return new WaitForSeconds(0.1f);

        //Unselect (ends the flash)
        hotspot .Deselect();
    }

Pretty easy to understand (hopefully), the projectile 'gets' the hotspot it came into contact with and then forces a .Select() / .Deselect() on it. This makes it flash using the highlight settings on the hotspot. Great!

But if instead I have a script on the hotspot itself...

private void Start()
    {
        thisHotspot = GetComponent<Hotspot>();
    }

    private void OnTriggerEnter(Collider other)
    {
        //Flash the object (highlight)
        StartCoroutine("Flash");
    }

    IEnumerator Flash()
    {
        //Set to selected (makes object trigger highlight)
       thisHotspot.Select();

        //Wait
        yield return new WaitForSeconds(0.1f);

        //Unselect (ends the flash)
        thisHotspot.Deselect();
    }
}

I get no flash at all, despite knowing for sure that the IEumerator is being run. I get no highlight activation despite using the exact same .Select() & .Deselect()

Any thoughts?

Comments

  • edited July 2019

    Please ignore this.

    As if Unity was just waiting for me to post on this forum, it's suddenly started working!

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.