Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Last active April 8, 2022 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtdekker/043891a1d27b0e7df6f3f064da6d70ad to your computer and use it in GitHub Desktop.
Save kurtdekker/043891a1d27b0e7df6f3f064da6d70ad to your computer and use it in GitHub Desktop.
// From: https://answers.unity.com/questions/801928/46-ui-making-a-button-transparent.html?childToView=851816
//
// @kurtdekker
//
// 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 on the Button, which lets the Button get touched
using UnityEngine;
using UnityEngine.UI;
#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();
}
#if UNITY_EDITOR
[CustomEditor(typeof(InvisibleGraphic))]
public class InvisibleGraphicEditor : Editor
{
public override void OnInspectorGUI()
{
// nothing
}
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment