Making Custom Gizmos

In this post, I will show you how to make a custom gizmo using code.

First, you need an image with an alpha channel. Here’s an example:

gem gizmo gimp

Okay, make sure you import your image into Unity. You should make a folder in your Unity project called “Gizmos” and put your gizmos in that folder. Next create a script. It’s as simple as 1, 2, 3 lines of code.

function OnDrawGizmos () {
    Gizmos.DrawIcon (transform.position, "gemGizmo.png");
}

That’s in JavaScript. Let me give it to you in C# as well..

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    void OnDrawGizmos() {
        Gizmos.DrawIcon(transform.position, "gemGizmo.png");
    }
}

Attach the script to your game object.

If you want to use a gizmo without code, keep reading.

As of Unity 3.5x, you can select your game object, look at the top left corner in the Inspector, and click the little icon with the arrow. Then click Other and choose your texture.

Advertisements

One thought on “Making Custom Gizmos

What Are Your Thoughts?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s