Raycast in Unity

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.

--

--

Unity Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store