Docsity

Unity Programmer Practice Exam Questions and Answers, Exams of Technology

Toggle sidebar
bg1
Unity Programmer Practice Exam
Question 1. Which keyword is used to define a method that can be accessed from other scripts?
A) private
B) public
C) protected
D) internal
Answer: B
Explanation: The `public` keyword makes a method accessible from other scripts and classes.
Question 2. What is the default value of an uninitialized `int` field in a C# class?
A) null
B) 0
C) 1
D) Undefined
Answer: B
Explanation: In C#, uninitialized integer fields are automatically set to 0.
Question 3. Which MonoBehaviour method is called before any Start methods?
A) Update
B) Awake
C) FixedUpdate
D) OnDestroy
Answer: B
Explanation: `Awake` is called before `Start` and is used for early initialization.
Question 4. What type of data structure would you use to store a collection of key-value pairs in C#?
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51

Partial preview of the text

Download Unity Programmer Practice Exam Questions and Answers and more Exams Technology in PDF only on Docsity!

Question 1. Which keyword is used to define a method that can be accessed from other scripts? A) private B) public C) protected D) internal Answer: B Explanation: The public keyword makes a method accessible from other scripts and classes. Question 2. What is the default value of an uninitialized int field in a C# class? A) null B) 0 C) 1 D) Undefined Answer: B Explanation: In C#, uninitialized integer fields are automatically set to 0. Question 3. Which MonoBehaviour method is called before any Start methods? A) Update B) Awake C) FixedUpdate D) OnDestroy Answer: B Explanation: Awake is called before Start and is used for early initialization. Question 4. What type of data structure would you use to store a collection of key-value pairs in C#?

A) Array B) List C) Dictionary D) Queue Answer: C Explanation: A Dictionary stores key-value pairs, making retrieval by key efficient. Question 5. Which Unity method is best for updating physics calculations? A) Update B) FixedUpdate C) LateUpdate D) OnDestroy Answer: B Explanation: FixedUpdate runs at fixed intervals and is ideal for physics operations. Question 6. What is the correct syntax to declare a boolean variable in C#? A) bool isActive = true; B) boolean isActive = true; C) var isActive = true; D) int isActive = true; Answer: A Explanation: The bool keyword is used to declare boolean variables in C#. Question 7. How do you access a component attached to a GameObject in Unity? A) GetComponent()

C) Serializes a class D) Allows runtime editing Answer: A Explanation: [SerializeField] exposes private fields in the Unity Inspector for editing. Question 11. Which type of loop is best for iterating over all elements in a collection? A) while B) for C) foreach D) do-while Answer: C Explanation: foreach is designed for iterating over each element in a collection. Question 12. What is the main difference between a class and a struct in C#? A) Classes are value types B) Structs support inheritance C) Classes are reference types D) Structs can have constructors Answer: C Explanation: Classes are reference types, while structs are value types. Question 13. Which MonoBehaviour method should be used to clean up resources before a GameObject is destroyed? A) Start B) Awake

C) OnDestroy D) Update Answer: C Explanation: OnDestroy is called before the object is destroyed, suitable for cleanup. Question 14. How do you declare an array of integers with 10 elements in C#? A) int[] numbers = new int[10]; B) int numbers[10]; C) int[] numbers = int[10]; D) array numbers = 10; Answer: A Explanation: This is the correct syntax for declaring an array of 10 integers. Question 15. What is the recommended way to instantiate a prefab in Unity via script? A) new GameObject() B) Instantiate(prefab) C) Create(prefab) D) GameObject.Instantiate(prefab) Answer: D Explanation: GameObject.Instantiate(prefab) correctly instantiates a prefab in Unity. Question 16. Which Unity method is commonly used for smooth camera following after all physics updates? A) Update B) FixedUpdate

D) Improves lighting Answer: B Explanation: Prefabs enable developers to create reusable and scalable objects. Question 20. Which function loads a new scene in Unity synchronously? A) SceneManager.LoadScene("SceneName"); B) LoadSceneAsync("SceneName"); C) Application.LoadLevel("SceneName"); D) Scene.Load("SceneName"); Answer: A Explanation: SceneManager.LoadScene loads a scene synchronously. Question 21. Which component is essential for simulating physics on a GameObject? A) Rigidbody B) Collider C) Transform D) MeshRenderer Answer: A Explanation: The Rigidbody component enables physics simulation. Question 22. What is the result of using the isTrigger property on a Collider? A) Collider ignores physics B) Collider detects triggers but not physical collisions C) Collider becomes invisible D) Collider increases size

Answer: B Explanation: Setting isTrigger to true detects trigger events, not physical collisions. Question 23. What method is used to apply a force to a Rigidbody? A) AddForce() B) ApplyForce() C) Move() D) SetVelocity() Answer: A Explanation: AddForce() applies a force to the Rigidbody for movement or impact. Question 24. How do you access the Transform component of a GameObject in a script? A) gameObject.Transform B) gameObject.GetTransform() C) transform D) gameObject.GetComponent() Answer: C Explanation: The transform property is a shortcut to the GameObject’s Transform. Question 25. What is the default access modifier for class members in C#? A) public B) private C) protected D) internal Answer: B

Question 29. What is the primary use of the OnTriggerEnter method in Unity? A) Detecting when a collider enters a trigger B) Applying force C) Setting transform D) Updating animations Answer: A Explanation: OnTriggerEnter is called when a Collider enters a trigger zone. Question 30. What Unity class allows you to manipulate an object's position, rotation, and scale? A) Transform B) Rigidbody C) MeshRenderer D) Animator Answer: A Explanation: The Transform class controls position, rotation, and scale. Question 31. Which of the following methods is used to execute logic when a collision occurs? A) OnCollisionEnter B) OnTriggerExit C) OnDestroy D) Update Answer: A Explanation: OnCollisionEnter is called when a collision occurs.

Question 32. What does the public keyword do when applied to a field in a MonoBehaviour script? A) Makes it visible in Inspector and accessible from other scripts B) Makes it visible only to child classes C) Makes it hidden from Inspector D) Makes it read-only Answer: A Explanation: public fields are visible in the Inspector and accessible from other scripts. Question 33. Which Unity system allows for pathfinding and navigation for AI? A) NavMesh B) MeshRenderer C) Canvas D) Animator Answer: A Explanation: NavMesh provides baked navigation data for AI pathfinding. Question 34. How do you assign a value to a variable in C#? A) int x = 5; B) x := 5; C) x <- 5; D) int x == 5; Answer: A Explanation: The assignment operator = is used to assign values. Question 35. What is the correct way to iterate through a List in C#?

B) OnEnable C) OnDestroy D) Update Answer: B Explanation: OnEnable is called when the GameObject is enabled. Question 39. How do you access the main camera in a Unity scene via script? A) Camera.main B) GameObject.Find("MainCamera") C) FindCamera() D) MainCamera.Get() Answer: A Explanation: Camera.main provides easy access to the scene’s main camera. Question 40. What is the recommended method for handling user input in newer Unity projects? A) Input Manager B) Input System package C) Event System D) InputField Answer: B Explanation: The Input System package offers advanced input handling features. Question 41. Which function is used to destroy a GameObject in Unity? A) Destroy(gameObject) B) Remove(gameObject)

C) Delete(gameObject) D) Dispose(gameObject) Answer: A Explanation: Destroy(gameObject) removes the GameObject from the scene. Question 42. What is a benefit of using C# properties over public fields? A) Allows encapsulation and validation B) Increases performance C) Reduces code size D) Makes fields visible in Inspector Answer: A Explanation: Properties allow for encapsulation and additional logic on access. Question 43. How do you load an asset from the Resources folder at runtime? A) Resources.Load("path") B) AssetBundle.Load("path") C) LoadAsset("path") D) AssetDatabase.LoadAssetAtPath("path") Answer: A Explanation: Resources.Load<T>() loads assets from the Resources folder. Question 44. What is the function of the LateUpdate method in Unity? A) Runs after Update for final adjustments B) Handles physics updates C) Runs before Awake

Answer: A Explanation: SetActive(true/false) controls the GameObject’s active state. Question 48. What does the keyword static mean when used with a method? A) The method belongs to the class, not an instance B) The method cannot be accessed C) The method is private D) The method is virtual Answer: A Explanation: Static methods are called on the class itself, not on object instances. Question 49. Which class is used for handling lists of objects in C#? A) List B) ArrayList C) Collection D) Dictionary Answer: A Explanation: List<T> is a generic collection for storing lists of typed objects. Question 50. What is the purpose of the [Serializable] attribute in Unity? A) Allows objects to be serialized for saving/loading B) Makes fields visible in Inspector C) Makes a class public D) Enables inheritance Answer: A

Explanation: [Serializable] allows the class to be serialized for data persistence. Question 51. Which method is called when a MonoBehaviour script is disabled? A) OnDisable B) OnDestroy C) Update D) Awake Answer: A Explanation: OnDisable is called when the script or GameObject is disabled. Question 52. How do you change the position of a GameObject via script? A) transform.position = new Vector3(x, y, z); B) gameObject.SetPosition(x, y, z); C) position = (x, y, z); D) gameObject.MoveTo(x, y, z); Answer: A Explanation: Assigning to transform.position updates the GameObject’s position. Question 53. What is the main advantage of using delegates in C#? A) Enables event-driven programming B) Reduces memory usage C) Increases execution speed D) Makes code public Answer: A Explanation: Delegates allow methods to be invoked in response to events.

Question 57. Which MonoBehaviour method is called when the script is first initialized? A) Awake B) Start C) OnEnable D) FixedUpdate Answer: A Explanation: Awake is called when the script instance is loaded. Question 58. How do you create a new List of integers in C#? A) List myList = new List(); B) int[] myList = new List(); C) List myList = int[]; D) int myList = new List(); Answer: A Explanation: This is the syntax for declaring a new List of integers. Question 59. Which method is used to set a parameter in the Animator Controller? A) animator.SetBool("param", true); B) animator.ChangeParam("param", true); C) animator.SetParameter("param", true); D) animator.Set("param", true); Answer: A Explanation: SetBool, SetFloat, SetInteger, and SetTrigger set Animator parameters. Question 60. What Unity method is used to detect when a Collider exits a trigger?

A) OnTriggerExit B) OnTriggerEnter C) OnCollisionExit D) OnDestroy Answer: A Explanation: OnTriggerExit is called when a Collider exits a trigger zone. Question 61. How do you retrieve the number of elements in a List? A) list.Count B) list.Length C) list.Size D) list.Total Answer: A Explanation: The Count property returns the number of elements in a List. Question 62. What is the primary function of the Update method in Unity? A) Runs game logic every frame B) Handles physics updates C) Cleans up resources D) Initializes components Answer: A Explanation: Update is used for per-frame game logic. Question 63. What is the effect of making a field public in a MonoBehaviour? A) Field is visible in Inspector and accessible from other scripts