Editing The Generic Unity Scripts.

If you have been using unity for awhile you must likely have had to write some code to accomplish whatever you need your gameobject to do. Particularly if your favorite language to program this scripts in is C#. Your Probably familiar with see something like this when opening a newly created script.

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}
}

When you first start writing scripts in unity this is good the already inserted comments describe exactly what each method is used for. However after some time I found myself constantly removing the comments just to tidy up my scripts when i’m done.

To fix this were going to edit the default NewBehaviourScript.cs in unity and remove the commented lines.

Editing The NewBehaviourScript

To begin navigate to one of the below directories using your operating systems file explorer.

If using Unity 4.x

 C:\Program Files\Unity\Editor\Data\Resources\

If using Unity 5.x

 C:\Program Files\Unity\Editor\Data\Resources\ScriptTemplates

 

ScriptTemplates folder in unity 5.0.0f4
ScriptTemplates folder in unity 5.0.0f4

 

Next, open the file NewBehaviourScript.cs in your favorite code editor and remove the commented lines. When finished save the file.

Thats it your done!, enjoy all the extra time you’ve quite potentially saved yourself. You can thank me later!

 

Extending The Lesson

To take what we just learned one step further. Lets add an additional using statement

I can only speak for myself when I say. A majority of my scripts Hardly use “System.collections” theres a time and a place but usually my scripts don’t take advantage of anything inside. I am however going to keep it in because the compiler is usually intelligent enough to not load anything were not using because its smart like that.

What I will add is this:

using System.Collections.Generic;

If your wondering what it does you can take a gander of it over at Microsofts Website

It basically allows you to implement

  • Lists
  • Hashsets
  • Enumerators
  • and more…

 

Comments are closed.