Forum rules - please read before posting.

Hiding an animation that is a child of a Hotspot that is disabled

edited March 7 in Technical Q&A

This is for a 2D game, so the built-in hotspot highlight system does not work for me. Basically, I want to be able to somehow highlight all the active hotspots when necessary. This would be done by an animation of a "sparkle", that would show over all the active/enabled hotspots at any given time of the gameplay.

I thought I could achieve this by putting instances of this object with the sparkle animation as a child of each hotspot so that it would show only when the hotspot is enabled and not show when disabled.

But it does not work. The animations that started in an enabled hotspot do not disappear when the hotspot has been disabled and vice versa.

Is there a way I can make this work?

Comments

  • When Hotspots are disabled, their GameObects are still enabled - they get put onto a different layer.

    You would need a custom script that reads the Hotspot's IsOn function and enables/disables the child object accordingly.

  • Could you please help me? I cannot script. I tried to generate something in chat GPT, but surely it is a mess. I tried the script to be automatic for all the hotspots in the scene (so that I wouldn't have to attach it to each hotspot manually).

    using UnityEngine;
    using AC;
    using System.Collections.Generic;
    
    public class HotspotChildManager : MonoBehaviour
    {
        private List<AC.Hotspot> hotspots = new List<AC.Hotspot>();
    
        void Start()
        {
            FindAllHotspots();
            UpdateAllHotspotChildren();
        }
    
        void Update()
        {
            UpdateAllHotspotChildren();
        }
    
        private void FindAllHotspots()
        {
            hotspots.Clear();
            hotspots.AddRange(FindObjectsOfType<AC.Hotspot>());
        }
    
        private void UpdateAllHotspotChildren()
        {
            foreach (AC.Hotspot hotspot in hotspots)
            {
                if (hotspot != null)
                {
                    bool isHotspotOn = hotspot.IsOn(); // Correct use of AC.Hotspot.IsOn()
    
                    Transform firstChild = hotspot.transform.childCount > 0 ? hotspot.transform.GetChild(0) : null;
    
                    if (firstChild != null)
                    {
                        firstChild.gameObject.SetActive(isHotspotOn);
                    }
                }
            }
        }
    }
    
  • Have you tried the script? From what you describe, it looks like it should do the job.

  • I did. My mistake; I thought it didn't work when, in fact, I had the Hotspot I was testing at Z position: -10, which made the child with the animation hidden. It does work well now!

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.