Realizarea unui Main Menu
Hotkeys
Folders inside unity
Unity reserves some project folder names to indicate that the contents have a special purpose. There are a number of folder names that Unity interprets as an instruction that the folder's contents should be treated in a special way. Some of these folders have an effect on the order of script compilation. These folder names are:
Asset Bundles, Resources and StreamingAssets
There are several ways to serve up resources to Unity at runtime, and each method has its place in game development: asset bundles, resource folders, and streaming assets.
# Asset Bundles:
Asset bundles let you deliver content to your application outside of your Unity build. Generally, you'd host these files on a remote web server for users to access dynamically. Asset bundles can contain anything from individual assets to entire scenes, which also makes them ideal for delivering downloadable content (DLC) for your game.
# Resource Folders:
The Resource folders are bundled managed assets. That means they will be compressed by Unity, following the settings you apply in the IDE. Unlike Asset bundles, resource folders are baked into the Unity Player as part of the game. You can do this by adding the required assets to a folder named Resources in your assets directory.
# Streaming Assets:
Like Resource Folders, a Streaming Assets directory can be created by intuitively creating a folder named StreamingAssetsthat, that you can use to put bundled un-managed assets. Unlike Resource folders, this directory remains intact and accessible in the Unity player. This creates a unique access point for users to add their own files to the game.
Prefabs In Unity 3d
Prefab in Unity 3D is referred for pre-fabricated object template (Class combining objects and scripts). At design time, a prefab can be dragged from project window into the scene window and added the scene's hierarchy of game objects. If desired the object then can be edited.
At the runtime, a script can cause a new object instance to be created at a given location or with a given transform set of properties.
In Unity scripting, there are a number of event functions that get executed in a predetermined order as a script executes. This execution order is described below:
Difference between Start and Awake Unity Events
Awake as ” initialize me” and Start as ” initialize my connections to others.” You can't rely on the state of other objects during Awake, since they may not have Awoken themselves yet, so it's not safe to call their methods.
Start function is called only if the script component is enabled. Awake function called when the script instance is being loaded.
If the script is NOT enabled at the beginning of your game, and you don't need the variables to be initialized, start() would be saving performance as awake() would be called regardless.
Difference between Update, Fixed Update and Late Update.
Update: (Most things)
FixedUpdate:(Physics things)
LateUpdate:(After update)
Script compilation order inside Unity
There are four separate phases of script compilation. The phase where a script is compiled is determined by its parent folder. In a script compilation, the basic rule is that anything that is compiled in a phase _after_ the current one cannot be referenced. Anything that is compiled in the current phase or an earlier phase is fully available.
The phases of compilation are as follows:
A common example of the significance of this order occurs when a UnityScript file needs to reference a class defined in a C# file. To achieve this, you need to place the C# file inside a Plugins folder, and the UnityScript file in a non-special folder. Because C# code is compiled before JS code, so in general, while JS code can access C# classes, the opposite is not possible If you don't do this, an error is thrown saying that the C# class cannot be found.
Variables and Parameters
Variables can be controlled from the Unity Editor as parameters, as long as they are defined public or serializable. We can use both simple variable or arrays.
public float speed; public Sprite[] images; private float internalBleed; //cannot be controller from Unity Editor interface [SerializeField] private Text scoreText; [SerializeField] private GameObject[] enemyTypes;
MonoBehaviour Event Execution Order
Ordered by first to last method to execute.
private void Awake() { /* Called when the script is being loaded */ } private void OnEnable() { /* Called every time the object is enabled */ } private void Start() { /* Called on the frame when the script is enabled */ } private void Update() { /* Called once per frame */ } private void LateUpdate() { /* Called every frame after Update */ } private void OnBecameVisible() { /* Called when the renderer is visible by any Camera */ } private void OnBecameInvisible() { /* Called when the renderer is no longer visible by any Camera */ } private void OnDrawGizmos() { /* Allows you to draw Gizmos in the Scene View */ } private void OnGUI() { /* Called multiple times per frame in response to GUI events */ } private void OnApplicationPause() { /* Called at the end of a frame when a pause is detected */ } private void OnDisable() { /* Called every time the object is disabled */ } private void OnDestroy() { /* Only called on previously active GameObjects that have been destroyed */ }
Physics updates on a Fixed Timestep are defined under Edit ▸ Project Settings ▸ Time ▸ Fixed Timestep and may execute more or less than once per actual frame.
private void FixedUpdate() { /* Called every Fixed Timestep */ }
Debug
Debug.Log(transform.position); Debug.Log("text");