Create a new script in Unity, open it up in the Visual Studio, and you will see this:
using UnityEngine; using System.Collections; public class MainPlayer : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }
This is great if you are an absolute beginner and following a tutorial, or if you need these exact two functions. But even then, the comments can get annoying. Also, the end-of-line formatting may be different and you would get the warnings in the editor.
Granted, these are small annoyances. But we can easily get rid of all of them. So why keep them around?
Open up the Unity installation folder. Assuming you used the Hub to install Unity (and you should), the default installation path for the editor on Windows is:
C:\Program Files\Unity\Hub\Editor
For Mac:
/Applications/Unity/Hub/Editor
From there, select the editor version. Mine is 2019.3.0a11. Then proceed to Editor\Data\Resources\ScriptTemplates. The full path for Windows then becomes:
C:\Program Files\Unity\Hub\Editor\2019.3.0a11\Editor\Data\Resources\ScriptTemplates
For Mac:
/Applications/Unity/Hub/Editor/2019.3.0a11/Editor/Data/Resources/ScriptTemplates
And there you will see the templates for different kinds of scripts and shaders. Of course, you are free to edit any of them. The one I’m mainly interested in is “81-C# Script-NewBehaviourScript.cs.txt”. Open it up in any editor and you should see something like this:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class #SCRIPTNAME# : MonoBehaviour { // Start is called before the first frame update void Start() { #NOTRIM# } // Update is called once per frame void Update() { #NOTRIM# } }
Edit it as you wish, don’t forget to change the end-of-line settings and save the file. Here is what I’m usually using:
using UnityEngine; public class #SCRIPTNAME# : MonoBehaviour { }
Keep in mind that since this is a “Program Files” folder, you need to have admin privileges to save or change files over here. If you are using notepad, just save the file somewhere else, then copy-paste it in this folder and replace with the old one.
If you are using Notepad++ or VSCode, it will ask you if you wish to re-launch it with the administrative privileges. Do it, and then you can save the file in the same directory.
There you go, now the new script will look like this by default:
using UnityEngine; public class MainPlayer : MonoBehaviour { }
Хорошая статья
do these have any names?
#SCRIPTNAME#
#NOTRIM#
And if so, are there more of those that can be applied?
Hi Hernan!
Unfortunately I couldn’t find names for those arguments, and I don’t know if there are others. As far as I can tell this is not documented by Unity. But you can check the rest of the templates for more examples 🙂
I see where you’re coming from, Amjad. However, I think there might be another way to approach the issue.