1 - What is a Coroutine?
A coroutine is like a function that has the ability to pause execution and return control to Unity but then to continue where it left off on the following frame. It is useful to make procedural animations or a sequence of events over time.
Source : https://docs.unity3d.com/Manual/Coroutines.html
2 - What is a shader?
Shaders are small scripts that contain the mathematical calculations and algorithms for calculating the colour of each pixel rendered, based on the lighting input and the Material configuration.
Source : https://docs.unity3d.com/Manual/Shaders.html
3 - What is the difference between the Start, Awake and OnEnable methods?
Start is called on the frame when a script is enabled just before any of the Update methods is called the first time. Awake is called when the script instance is being loaded. OnEnable is called when the object becomes enabled and active. Execution order is : Awake, OnEnable, Start.
Source : https://docs.unity3d.com/ScriptReference/MonoBehaviour.Start.html
Source : https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html
Source : https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnEnable.html
Source : http://answers.unity3d.com/questions/217941/onenable-awake-start-order.html
4 - In the mock-up below, pin down every elements to be cut into sprites to recreate a scene Into Unity. The goal is to optimize draw calls and memory usage.
- The Sky can be cut as a one pixel wide sprite and be put on a Transform with a stretched X scale
- The moutains can be cut as a single sprite
- Only the largest palm tree should be cut as the others are just scaled down, rotated and mirrored duplicates
- The circles for the sun and it's shadow can be created in Unity. Right-click in the project hierarchy, Create, Sprites, Circle. This creates a Vector shape so it can be scaled to any size without using too much memory. You can color the sprite using the Color property of the SpriteRenderer
- Use the same technic as the sun to create a square that will fill most of the scene with a plain sand color.
- Cut a sprite for the darker sand
- For the frog Bubble, use the Sprite Editor to achieve the nine slice technic
- The arrow at the bottom of the bubble is a single sprite
- A single frog can be cut in white and gray and can be duplicated and colored differently using the Color property of the Sprite Renderer
- The eyes, mouth and waterlily have to be cut as seperated sprites since they are not colored like the rest of the frog's body
Source for slicing a sprite : https://www.youtube.com/watch?v=WFQcc1GUe7U
5 - What can be modified in the code below to improve it?
- Don't use GameObject.Find, especially not inside the update because it's slow
- Limit the use of tags, search object by components instead when possible because maintaining tags can cause problems if a tag name changes
- Instead of looking for objects every frame (it's slow), cache the list of EnnemyController inside the class and use a Delegate to know when an ennemy dies so this class can maintain the list of ennemies alive and call the Victory method when all ennemies are dead
void Update() { GameObject[] objects = GameObject.FindGameObjectsWithTag("Ennemy"); if (objects.Length == 0) Victory(); else foreach (GameObject obj in objects) obj.GetComponent<EnnemyController>().DoAction(); }
6 - Describe a way to create a mini-map in the corner of a screen to display in real time the surroundings or the player.
Use a RenderTexture (Right-click in the project hierarchy, Create, Render Texture) to render a special, top down view, mini-map camera inside this texture. Bind this texture to a UI Image component. You can also add an icon over the head of you character that will be on a layer only rendered by the mini-map camera.
Source : https://docs.unity3d.com/ScriptReference/RenderTexture.html
7 - There is an instance of a prefab on the scene A and another instance of the same prefab on the scene B. We modify the "Speed" field of the prefab in the scene B to 385 and then we change the same field of the prefab in the scene A to 500 before hitting the Apply button on the prefab in the scene A. What's the value of the "Speed" field : on the prefab, on the prefab instance in the scene A and on the prefab isntance in the scene B?
Prefab : 500
Scene A prefab instance : 500
Scene B prefab instance : 385
Source : https://docs.unity3d.com/Manual/Prefabs.html
8 - A piece of code inside the Update method makes a UI panel slide in the scene using transform.Translate(1, 0, 0). On a first generation iPad, the panel takes 2 seconds to animate to the center of the screen while it only takes 1 second on an newer iPad. Why does this happen and how can we fix it?
Devices running on different specs can have different framerates. In this case, maybe the game is running at 30 fps on the older iPad and running at 60 fps on the newer one. Update is called once per frame so that's why the animation complete faster on the newer iPad. To make the translation move at a constant speed, multiply the translation values by Time.deltaTime which is the time since the last frame. Another option would be to execute the code inside the FixedUpdate method which always run at a fixed interval of time.
Source : https://docs.unity3d.com/ScriptReference/Time-deltaTime.html
Source : https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html
9 - In a 2D platformer game, the character is a GameObject moved by physics with a RigidBody2D and a BoxCollider2D. On the scene, there are coins made of a Sprite and a CircleCollider2D with the IsTrigger parameter activated. In the caracter script, we want to increment the score by one when the coin is collided. But, the code below is never reached when the character runs into a coin. Why?
OnTriggerEnter is a Unity method that works with 3D physics and RigidBody components. For 2D physics and RigidBody2D components, we use the OnTriggerEnter2D method.
Source : https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter2D.html
void OnTriggerEnter(Collider collider) { Score += 1; }
10 - Give an example of things we could do inside another Thread beside the Unity main Thread.
You can do anything in other Threads except using Unity API methods themselves across different threads, as they are not thread-safe.
Source : http://answers.unity3d.com/questions/908054/unity-5-multithreading.html