Game Development Reference
In-Depth Information
Running scripts in the Editor folder
The last little tidbit you should be aware of surrounds scripts and their execution.
If you put a script in the Editor folder, it will be executed when you are in the editor.
However, what about all your other scripts?
Sure you can run the game and see the script running, but that doesn't help you when you
are in the editor. What if you want to see the effect of your script while manipulating
game objects in your scene? If you are using GUI controls, this becomes even more critic-
al when you are trying to place controls on the screen.
Thankfully, there is a way to force the editor to run your script, and all it takes is yet an-
other attribute called ExecuteInEditMode added to your class. To show this, let's
open the CommandBar script under Assets\Scripts in our project and add the
[ExecuteInEditMode] attribute to that class as follows:
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class CommandBar : MonoBehaviour
{
Now when you open up the Battle scene, CommandBar will always be drawn as
shown here:
Search WWH ::




Custom Search