how to create a script in unity editor

 Script is life of a game. Script allow you to control you gameObjects as you want. Unity support C# programming language (called as C-Sharp). From this post we will learn scripting in unity. and first part of learning is creating a script so now start creating script. There are some way of creating script let's take a look.
1. You can create a new script by navigating Assets > Create > C# Script  

creating script in unity editor

as you click on C# Script a new script will be created in project panel with a name newMonobehaviorScript to rename you have to give a name to script whatever you want.

created script in project panel of unity editor

2.  You can also create a script by clicking on plus(+) icon in top left corner of project panel and 
creating a c# script in unity editor by project panel

click C# Script to create a new script when you click c# script it will prompt to rename it.
creating c# script

3. There is a other way of creating a script in unity by right clicking in project panel and then clicking C# Script will create a new script.

These are some way of creating a script now let take a look what a script contain. By double clicking on the script it will be opened in visual studio code editor or whatever how set in Edit > Preferences > External tools. 

opened C# script in visual studio code

 Scripts are attached a component to gameObjects so to see working of a script need to attach to a gameObject. 

You must take care that script name and class name should exactly match.
Our script already contains to function Start() and Update(). 

Start() :- Start function will run only once when a scene is loaded.

Update() :- Update function run at each frame mean it will run several time in a second so to use a oher function  in game you have to call it in Update function. 


Popular posts from this blog

How to fix Android Gradle Build failed error in unity

Changing position of gameObjects in unity by C# script

WaitForSeconds and coroutine in unity | delaying a code action for some time in C#

Unity ads install error from package manager

SerializeField and HideInInspector in unity in C# script

playing audio in unity by C# script

how to setup unity ads in mobile game

GetComponent method in unity to access component by C# script

Variables in C# script in unity

Activating and deactivating gameObjects in unity by C# script