Recall & Review
beginner
What is raycasting in Unity?
Raycasting is like shining an invisible laser beam from a point in a direction to check if it hits any objects. It helps detect objects in the game world.
Click to reveal answer
beginner
How do you create a simple raycast in Unity?
Use
Physics.Raycast(origin, direction, out hitInfo, maxDistance). It sends a ray from origin in direction and stores hit details in hitInfo if it hits something within maxDistance.Click to reveal answer
intermediate
What does the
RaycastHit object provide?RaycastHit gives information about what the ray hit, like the exact point of contact, the surface normal, and the object's collider.Click to reveal answer
beginner
Why use raycasting for detection in games?
Raycasting is efficient for checking line of sight, shooting bullets, or detecting if the player can interact with objects without checking every object manually.
Click to reveal answer
beginner
What happens if a raycast does not hit any object?
The raycast returns
false, meaning nothing was detected in that direction within the specified distance.Click to reveal answer
What does
Physics.Raycast return if it hits an object?✗ Incorrect
Physics.Raycast returns true when the ray hits an object.
Which parameter stores information about the object hit by the raycast?
✗ Incorrect
RaycastHit hitInfo stores details about the hit object.
What is the purpose of the
maxDistance parameter in raycasting?✗ Incorrect
maxDistance limits how far the ray travels to detect objects.
If you want to detect objects only on certain layers, what should you use?
✗ Incorrect
Use a LayerMask to filter which layers the raycast can hit.
What does the
hitInfo.point represent?✗ Incorrect
hitInfo.point is the exact spot where the ray touched the object.
Explain how raycasting works in Unity and how it helps detect objects.
Think about sending an invisible line and checking what it touches.
You got /5 concepts.
Describe a simple Unity script snippet that uses raycasting to detect if the player is looking at an object within 5 meters.
Use the camera's position and forward direction for the ray.
You got /6 concepts.