Unity Basics
Folder structure
graph LR
A[Unity] --> B(Hierachy);
B --> D(Game scene objects);
A --> C(Inspector);
B -->|select affects| C;
A --> E(Project);
E --> F(Assets);
F --> G(Scenes);
F --> H(Prefabs);
F --> I(Materials);
F --> J(Scripts);
F --> P(PhysMaterials);
G --> B;
Operations
- At Hierarchy, you can create any simple game objects via right click.
- Select game object affects whats shown in Inspector.
- z-axis: forward and backward, x-axis: left and right, y-axis: up and down.
- alt+left key: rotate, middle key: translate, e: rotation tool, r: scaling tool, w: move tool for object, these tools affect transform in inspector.
- Rename F2 either in Inspector or SampleScene.
- Can create any thing in assets, materials, scripts, etc.
- To apply a property like material to an object in scene, you can drag it to Hierarchy object or object in the scene.
- Shift+F : Focus on your object selected.
- Ctrl+D: Duplicate object.
- Making an object a child of another object: drag the child to the parent in hierarchy.
- Materials: store color material, Prefabs: store reusable objects which can be changed easily, Scenes: store all samplescenes, .
- Drag object from hierarchy to prefab to create a storage of reusable objects.
- Create empty object, it acts like an empty folder to store all objects.
- Edit → Preferences → External Tools #&8594 External Script Editor: vscode.
- Add Component: can add behavior scripts and physics to the object.
- Rigid body component: can apply force like gravity.
- Script component: make sure your script class name is matching your object name.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
- Edit → Project settings → Input Manager: It shows the inputs can be used by player.
- Useful built-in methods in C# script,
void Start()
void Update()
void FixedUpdate()
void OnCollisionEnter(Collision collision)
void OnCollisionExit(Collision collision)
void OnTriggerEnter(Collision other)
- public (/SerializeField private) variable (/field) in the script will export to Unity. Can drag an empty object to connect with it.
public datatype dataname;
[SerializeField] private datatype dataname;
- Layer Filtering: Click object → Add Layer named Player → Change Layer to Player → Edit → Project settings → Physics uncheck Player layer
- In order to import meshes from blender, you need to scale it in blender and import it and set scale as 1 1 1. Remove the box collider and add component again as well, so the collider becomes the right shape.
- Remember to export from blender as fbx.
- Remember to import color scheme as new material.
References
- Welcome to the Unity Scripting Reference!
- LEARN UNITY - The Most BASIC TUTORIAL I'll Ever Make
- Make Your FIRST COMPLETE Game in Unity | BEGINNERS