Raycast in Unity

Niraj Karki
Feb 14, 2022

3rd Person Zombie Shooter

Objective: Create a raycast using main camera

Here, center defines the center of the screen, rayOrigin defines the the point from where the ray is being cast.

Then define the RaycastHit variable which will then store the reference to the object being hit by the ray

And finally create a raycast which starts from rayOrigin and defines the Hit object which can then be used to define the type of object and what can be done with it. Here, only the name of the hit object is being displayed.

--

--