Scripting With C# In Unity

Introduction

This article demonstrates how to work with C# script in your Unity project.

Prerequisites

Unity Environment version 5.6.1

Working with C# scripts in Unity

Step 1

First, you have to open the Unity project. Create terrain, trees, and water. Add skyboxes in your project.

Go to  Assets and double click on "SampleScene".

Sample Scene will be displayed. Select and double click the Scripts folder.

Right click and select Create >> C# Scripts.

The C# scripts will be added into the scripts folder. Rename the script as MyScript. The default coding will be displayed in the right side.

Double click on MyScript.



Step 2

Unity mono development page will open. We can also use Visual Sudio. Click on the Project.

MyScript coding page will be opened. Click on the MyScript; the coding will be displayed.

Write a code for printing “Hello world” to start method. Save the program.

Return to the Unity window. Select "MyScript". The mono develop coding will be added into the Unity scripts. We cannot modify the coding for scripts in Unity, only change into code for mono develops.

Drag and drop the "MyScript" into main camera.

Click on the Main camera. The MyScript will be added in the Inspector window.

Click on the “Play” button. The Game View will be displayed. When you click on the Console, the Hello World message will be displayed.

Go to the mono develop, cut the print statement and paste into the update method. Save the program.

Click on the “Play” button. Game View will be displayed. Click on the console, the hello world messages will be displayed a number of times.

Summary

I hope you understood how to write C# scripts in your Unity project.


Similar Articles