Posts

Variables in C# script in unity

Image
There are many variables in unity some of them are usual as we use and some are created by unity API common variables are int - all you to store integer value. float - to store float value bool - give only true or false value string -   can store string value other variable are GameObject - it is used for accessing gameObject of unity AudioSource  - using audioSource as a variable Camera - use camera as a variable Using variables in Script you can define variables as <variable> <name> Like in above image i have define a public variable of type String that can store string value. if variable is public then it can be access by other script and value can be change in inspector. if nothing public or private is not written then it will be private variable. You can change variable value in inspector after attaching to a gameObject     When you create a script in unity it will work as a component and as you attach it to a gameObject it will show you all public variables can be edi

how to create a script in unity editor

Image
 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    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. 2.  You can also create a script by clicking on plus(+) icon in top left corner of project panel and  click C# Script  to create a new script when you click c# script it will prompt to rename it. 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 conta

Scene Visibility in unity editor

Image
You can hide or show gameObjects by Unity scene visiblity it is very useful in creating complex scenes where it is difficult to see specific gameObjects. In the above image you will find an icon look like eye at very beginning of each gameObject in hierarchy window. You can hide or GameObject in scene view by by just clicking on that eye. if you click on a parent gameObject to hide it will also hide its all child object. You will see three type eye  1. One which is fully visible eye that show GameObject is visible. 2. Second in which eye is crossed that show gameObject is hided in scene view. 3. Third in which there is  a point at lower end of eye which means one or more child gameObject is hided.  Scene View Control Bar You can control your game audio and lighting enabled and various other options of scene view. These controls affect only game in editor and does not affect build game. Now we will discus all menus one by one Draw Mode Menu First one drop down is used how you want to se

Grid snapping in unity editor

Image
 There are virtual grid in the editor's Scene view that help you to align GameObjects snapping(moving) to the nearest grid You can change this grid to any axis x,y,or z.  Aligning (Moving) to the grid GameObject can be move to the single axis or along all axis to the closest grid. To move a gameObject to closest grid open Grid and snap window by either method From Main unity menu, Choose Edit>Grid and Snapping Setting From the grid visible in scene view menu open the overflow menu and choose Edit Grid and Snap Setting and you can reset all grid settings by just clicking reset as shown in below image. in grid and snap setting  you will find Align selection sector click on x, y, or z button or to all axis or you can did the same work by selecting the gameobject and pressing Ctrl + \ key together for windows and command+\ key for macOS. You can use increment Snap Section to modify how much you want to move and along which axis. Showing and Hiding Grid lines By toggling the grid vis

Positioning GameObjects in unity editor

Image
 You can change transform component of any gameobjects by manipulating mouse on any Gizmo axis or you can change values of transform component in inspector window. transform has the following tools. let's take a look  Move tool You can select move tool in toolbar or can select by pressing hotkey W.  At the center of Move Gizmo there are three small squares by dragging these square you can move gameObject along a plane and third axis remains constant. if you press shift key while dragging Move Gizmo squares will change to flat square. This flat square indicates that you can move gameObject in the direction scene view camera is facing.  For moving  to particular axis just drag any one of the axis that you want to change. Rotation tool While you select rotate tool or press hotkey E you will see spheres around gameObject and you can change rotation by dragging this sphere Gizmo. As with the Move Gizmo, the last axis you changed will be colored yellow. Think of the red, green and blue c

navigation and picking tools of Scene View in unity editor

Image
The Scene View The Scene view is your interactive world that we create. We can use scene view to select and position camera, character, lights and other gameObjects. Dealing with gameObjects is first skill that you learn. Scene View Navigation The Scene view has many navigation to move quickly around scene and these are following Scene Gizmo Scene Gizmo appears at the top right corner in scene view. It has conical arms with label x, y, and z. You can toggle perspective view on or off   In 2D mode Gizmo does not appear because you only have xy plane to navigate. Moving , orbiting and zooming in scene view For navigation in scene view moving, orbiting and zooming are key operations. Unity provide many tools for it. 1. Arrow Movement -  You can use arrow key to move around scene view. Arrow up and down key are used for moving forward and backward as scene is and left and right arrow use to move left and right side. You can use shift key to move fast. 2. Hand tool - You can select hand too

The Toolbar in Unity editor interface

Image
The Toolbar is present at the top of unity editor. It is the only unity editor interface that can not be rearrange. The Toolbar consist of several controls related to different part of unity editor. It is used for the transformation in scene view. First tool in the toolbar is Hand tool is used to pan around scene view. You can also select it by just pressing Q key from keyboard. Second tool is Move tool which is used to move gameobjects in scene view you can select it by just pressing W key in keyboard. Third tool is used to rotate objects in scene view and to access it press E key. Forth one is for scaling gameObjects and can be accessed by pressing key R. Last fifth and sixth are rect transform and transform tool can be accessed by T & Y key respectively.  this tool is use to toggling the transform gizmo effect in scene view  these buttons are use for playing , pausing and stepping game in game view.  By clicking collab from dropdown it will launch Unity collaborate for accessing