There is a wide range of resources available to help create video games. Custom file formats are frequently created by developers using tools that convert 3D models and graphic image formats. Assets are viewed before they are included in the game using level editors and other tools. For the most part, game development tools are either developed in-house by the developer for a single game or are provided by the console maker (such as Nintendo or Microsoft) as part of an official game development kit. Unity 3d is an example of this kind of software.
What Is C# Unity 3D?
Unity3D is a user-friendly development environment and a strong cross-platform 3D engine. Unity should appeal to everyone who wants to create 3D games and applications for mobile, desktop, the web, and consoles. It is simple enough for beginners and powerful enough for experts.
Now that you have a good briefing on unity 3D Software, look at the Installation process of Unity 3D.
C# Unity 3D Installation
1. First, you will go to the Unity 3D Download website.
Here, you will download Unity Hub.
2. Then, you must open Unity Hub Setup and do the installation.
3. Now, open Unity Hub and go to the install tab to install an editor.
4. Now, you must select the recommended editor to install.
5. Now, you must select the option to install visual studio if it's not installed already and click on install.
Now, you will install the unity extension package for your Visual Studio.
1. So, open the Visual Studio installer. And click on modify.
2. Then you must go ahead and select Game development with Unity Extension and click on Modify.
And with this final step, Unity is successfully installed and ready to use on your system. Now, you will understand its User Interface.
Now, start with creating your first project.
1. Open the unity hub and click on New Project.
2. Then you must select "3D" to do a 3D project; then, you must give it a name, say, "Demo," and click "Create project."
3. You have to wait a few seconds for the editor to start the project.
And this is the Unity Project.
Now, you will look at each UI Component one by one.
C# Unity 3D User Interface
- First, you have two tabs at the top - Scene Tab and Game Tab.
- A sample scene tab would look like this.
- Then, you have the Game View Tab.
- Now, look at the hierarchy tab. This tab will contain all the Game objects for a game project. By default, a project comes with two game objects - the main Camera and Directional Light.
- Then, you have the Project tab at the bottom. This tab essentially contains all game asset files like scenes, materials, prefabs, textures, animation, Sound, etc.
- Next, you have Console Tab, and this is where all the errors and warnings will be listed when you debug your projects.
- Next, select a game object like the main camera. Have a look at the inspector Tab on the right.
If you look carefully, you will find some components in the inspector tab.
- First, you have the Transform component. This component will decide the game object's position, rotation, and size.
- Then you have another component named the camera. It is responsible for more camera-oriented settings like depth, the field of view, etc.
- You also have a Toolbar on the scene tab with different buttons responsible for certain actions.
1. First, you have the "view" tool in the toolbar. It is responsible for viewing around the scene map.
2. Next, you have the "move" tool in the toolbar. It is responsible for moving the game objects around on the scene map.
3. Then, you have the "Rotate" tool in the toolbar, responsible for rotating the game objects.
4. After that, you have the "Scale" tool in the toolbar. It is responsible for increasing the game objects' length, width, and height.
5. Next, you have the "Rect" tool in the toolbar. It is responsible for increasing the size of the game objects while maintaining their length, width, and height constant.
6. At last, you have is "Transform" tool in the toolbar. It is responsible for every action that every other tool except the view tool in the toolbar.
Now that you have brief knowledge about Unity 3D and its UI, do a small project.
C# Unity Game Object Creation
Now, start with creating a few important folders in the asset tab.
1. You can right-click in the project tab, click on Create, and select the folder to create one.
2. You must create multiple folders like Script, Materials, Textures, Prefabs, Sound, Animations, etc.
Now, go ahead and create a 3D Game Object like Cube
1. To create a Cube, you must right-click on the hierarchy Tab, click on 3D Object, and select the cube.
Here is the Cube:
2. You can now select the cube, see the inspect menu, and move, scale, or rotate it around anywhere on the scene map.
Now, create a material to give color to this game Object.
1. You will go to the materials folder and right-click to select create and choose the material.
2. You can name it GreenMaterial as we will give it a green color.
3. Now, by default, materials are white. So to color them, you must go to the inspector tab of that material and click on the color palette.
4. After choosing the color, you can drag the material over to the game object to apply it.
You have now explored Unity and its User interface. You have also learned to create a game object. Now, write a script for the Game Object.
C# Unity Script
1. To create a script, you will first go inside the scripts folder.
2. Then you must right-click on the space and click on create and select C# Script.
3. You will name it "Movement." Make sure to name them correctly. If you are a beginner and make a mistake, then it is better to delete the script and remake it with the correct name, or you might face errors while debugging.
4. You can double-click on the script to open it in Visual Studio.
This code will be responsible for moving the game object around in the game view.
//Movement Script to move the game object
public class Movement : MonoBehaviour
// Speed by which the block will move
public float velocity = 3;
// Update is called once per frame
Transform transformCam = Camera.main.transform;
Vector3 positionOfCam = new Vector3(transformCam.position.x, transform.position.y, transformCam.position.z);
Vector3 movingDirection = (transform.position - positionOfCam).normalized;
Vector3 movingForward = movingDirection * Input.GetAxis("Vertical");
Vector3 movingHorizontal = transformCam.right * Input.GetAxis("Horizontal");
Vector3 movement = Vector3.ClampMagnitude(movingForward + movingHorizontal, 1);
transform.Translate(movement * velocity * Time.deltaTime, Space.World);
5. You can save it now. Then, you must go back to your Unity and drag the Movement Script over to your GameObject Cube to apply it.
With this, you have a good grip on the fundamentals and User Interface for working with C# Unity 3D.
Master front-end and back-end technologies and advanced aspects in our Post Graduate Program in Full Stack Web Development. Unleash your career as an expert full stack developer. Get in touch with us NOW!
The next lesson in your C# training can be "How to create a game in Unity." You will be creating an Endless Runner game. Endless Runner is a game where the Player moves forward constantly while earning points and avoiding obstacles. The basic goal is to finish the level without falling into or clashing with the obstacles. Still, the level frequently repeats itself indefinitely, gradually increasing the difficulty until the Player collides with an obstacle.
Simplilearn is the world's most popular online Bootcamp for developing skills in the digital economy, and it's here to assist you in doing just that. Digital marketing and data science are just two topics we cover extensively in our online courses.
Simplilearn teamed with the Caltech CTME and the Indian Institute of Technology, Kanpur, to deliver their Software Development courses. These courses cover the fundamentals of data structures and algorithms and more advanced subjects such as Competitive Programming. As a software engineer, you will learn about data structures such as trees, graphs, and queues.
The comments section below is open for questions and comments about this 'C# Unity' tutorial. Happy learning!