Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Last active April 18, 2025 20:25
Show Gist options
  • Save kurtdekker/043891a1d27b0e7df6f3f064da6d70ad to your computer and use it in GitHub Desktop.
Save kurtdekker/043891a1d27b0e7df6f3f064da6d70ad to your computer and use it in GitHub Desktop.

Revisions

  1. kurtdekker revised this gist Apr 8, 2022. 1 changed file with 5 additions and 10 deletions.
    15 changes: 5 additions & 10 deletions InvisibleGraphic.cs
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,18 @@
    // From: https://answers.unity.com/questions/801928/46-ui-making-a-button-transparent.html?childToView=851816
    //
    // Invisibly-touchable Graphic component for Unity3D
    // @kurtdekker
    //
    // To use:
    // Touchable invisible non-drawing Graphic (usable with Buttons too):
    //
    // To make an invisible Button:
    //
    // 1. make a Button in the normal way
    // 2. delete the "Text" GameObject which comes below a Button as standard
    // 3. delete the "Image" which comes on a Button as standard
    // 4. drop this script, Touchable.cs, on to the button
    // 4. drop this script on the Button, which lets the Button get touched

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections.Generic;

    #if UNITY_EDITOR
    using UnityEditor;
    @@ -31,12 +32,6 @@ protected override void OnPopulateMesh(VertexHelper vh)
    vh.Clear();
    }

    // alternate for older versions of Unity (like really old)
    // protected override void OnFillVBO(List<UIVertex> vbo)
    // {
    // base.OnFillVBO(vbo);
    // }

    #if UNITY_EDITOR
    [CustomEditor(typeof(InvisibleGraphic))]
    public class InvisibleGraphicEditor : Editor
  2. kurtdekker created this gist Apr 11, 2021.
    50 changes: 50 additions & 0 deletions InvisibleGraphic.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    // From: https://answers.unity.com/questions/801928/46-ui-making-a-button-transparent.html?childToView=851816
    //
    // Invisibly-touchable Graphic component for Unity3D
    // @kurtdekker
    //
    // To use:
    // 1. make a Button in the normal way
    // 2. delete the "Text" GameObject which comes below a Button as standard
    // 3. delete the "Image" which comes on a Button as standard
    // 4. drop this script, Touchable.cs, on to the button

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections.Generic;

    #if UNITY_EDITOR
    using UnityEditor;
    #endif

    public class InvisibleGraphic : Graphic
    {
    public override bool Raycast(Vector2 sp, Camera eventCamera)
    {
    //return base.Raycast(sp, eventCamera);
    return true;
    }

    protected override void OnPopulateMesh(VertexHelper vh)
    {
    // We don't want to draw anything
    vh.Clear();
    }

    // alternate for older versions of Unity (like really old)
    // protected override void OnFillVBO(List<UIVertex> vbo)
    // {
    // base.OnFillVBO(vbo);
    // }

    #if UNITY_EDITOR
    [CustomEditor(typeof(InvisibleGraphic))]
    public class InvisibleGraphicEditor : Editor
    {
    public override void OnInspectorGUI()
    {
    // nothing
    }
    }
    #endif
    }