Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Hover Reveal script for Unity to show and hide object on mouse hover

Posted on November 30, 2025November 30, 2025 by Habibie

For 3D objects, use this script:

using UnityEngine;
using System.Collections.Generic;

public class HoverReveal : MonoBehaviour
{
    // List untuk menampung GameObject yang ingin dimunculkan
    public List<GameObject> visiblesOnHover;

    void Start()
    {
        // Secara default (saat game mulai), sembunyikan semua object di list
        SetVisibility(false);
    }

    // Dijalankan saat mouse menyentuh area collider object utama
    void OnMouseEnter()
    {
        SetVisibility(true);
    }

    // Dijalankan saat mouse keluar dari area collider object utama
    void OnMouseExit()
    {
        SetVisibility(false);
    }

    // Fungsi pembantu untuk mengatur aktif/tidaknya object
    void SetVisibility(bool state)
    {
        foreach (GameObject obj in visiblesOnHover)
        {
            if (obj != null) // Cek biar tidak error kalau ada slot kosong
            {
                obj.SetActive(state);
            }
        }
    }
}

For UI 2D objects, use this instead:

using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections.Generic;

public class UIHoverReveal : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    // List untuk menampung GameObject yang ingin dimunculkan
    public List<GameObject> visiblesOnHover;

    void Start()
    {
        // Secara default (saat game mulai), sembunyikan semua object di list
        SetVisibility(false);
    }

    // Dijalankan saat mouse menyentuh area UI element
    public void OnPointerEnter(PointerEventData eventData)
    {
        SetVisibility(true);
    }

    // Dijalankan saat mouse keluar dari area UI element
    public void OnPointerExit(PointerEventData eventData)
    {
        SetVisibility(false);
    }

    // Fungsi pembantu untuk mengatur aktif/tidaknya object
    void SetVisibility(bool state)
    {
        foreach (GameObject obj in visiblesOnHover)
        {
            if (obj != null) // Cek biar tidak error kalau ada slot kosong
            {
                obj.SetActive(state);
            }
        }
    }
}
Post Views: 25
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme