The Hierarchy window in Unity shows a list of all GameObjects in the current scene. Each GameObject in the Hierarchy represents an object in the game world, such as cameras, lights, and characters. Organizing objects in the Hierarchy helps manage and control different parts of your game.
// Creating a new GameObject and adding it to the hierarchy
GameObject newObject = new GameObject("MyNewObject");
The Scene window is where you visually lay out your game objects. It acts like a canvas where you can position, rotate, and scale objects to set up your game world. This view provides tools for creating and arranging elements and a preview of how objects will appear during gameplay.
// Moving an object in the scene
newObject.transform.position = new Vector3(0, 1, 0);
The Main Camera in Unity acts as the viewpoint through which players see the game world. You can adjust the Lens settings, such as Field of View (FOV), to control how much of the scene is visible. Other settings like Clipping Planes define the minimum and maximum distances at which objects are visible.
// Accessing and modifying the main camera's lens settings
Camera.main.fieldOfView = 60;
Camera.main.nearClipPlane = 0.1f;
Camera.main.farClipPlane = 1000f;
Directional Light is a type of light that mimics sunlight, casting parallel rays across the scene. It’s useful for outdoor scenes and provides even lighting. Adjusting settings like Intensity and Color changes the brightness and tone of the lighting, affecting the mood of the scene.
// Creating a directional light and setting its properties
GameObject lightGameObject = new GameObject("Directional Light");
Light lightComp = lightGameObject.AddComponent<Light>();
lightComp.type = LightType.Directional;
lightComp.color = Color.white;
lightComp.intensity = 1.0f;
In Unity, you can organize GameObjects in a parent-child hierarchy. A Parent object can control its Child objects' position, rotation, and scale. For example, if a parent object moves, all its child objects move with it. This setup is helpful for creating groups of objects that need to stay together, like a character holding a weapon.
// Setting a child object under a parent object
GameObject childObject = new GameObject("ChildObject");
childObject.transform.parent = newObject.transform; // Setting newObject as the parent