top of page

009-Custom Editor Exercise-3

1.1 Introduction

1. For this exercise open the folder 9 for the series.

2. Here we are given Test009 script. 

3.  Your job is to add 6 buttons to the current script that move the current gameObject in +x,-x,+y,-y,+z and -z direction respectively

1.2 Basic Script

1. Let us open Test009 script and take a look at its content.

image.png
1.3 Solution

1. First let us make a custom editor for Test009 and call it as Test009Editor.

2. Make sure that this inherits from Editor and has CustomEditor attribute on top of it pointing to Test009 script.

3. Let us override the OnInspectorGUI() method and also add base.OnInspectorGUI() to draw the default inspector.

image.png
1.3 Adding buttons

1. Let us add six buttons to the custom editors and call them as:

​

image.png
image.png
1.3 Getting reference to the target's gameObject

1. Let us get access to the current gameObject using target which points to the test009 monobehaviour.

image.png
1.4 Adding functionality to each button

1. Let us now add functionality to move the gameObject to each of the button.

2. This is going to be pretty straight forward and we are going to write them simply under each button.

image.png
1.5 Testing movement

1. Let us now move current gameObject by pressing buttons.

image.png
image.png

Before

After pressing forward button

End

Kindly support me through my Patreon account if you find these tutorials useful. Feel free to connect with me on Twitter. This support enables me to create more educational content.

bottom of page