How to Raycast using mouse | #UnityIn60Sec

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's learn how to pick object with our mouse using raycast first thing we're gonna do is create a script and call it reka script create a reference to our camera and put the main camera in it now we're gonna draw the ray start by getting the mouse position convert it to world point and using the debug we'll draw the ray now when we press play we can see array following the mouse to actually do something using this ring let's create something to do on mouse down first create a ring using the mouse position and convert to array then we'll create a way head object and using the physics dot raycast enter the ray out heat and the length of the way here it will be the object we click on for now let's print the name of the object we clicked on now we can click on any object but we only want to click on our enemies to fix this we'll create a layer mask create a public layer mask variable and add the variable to a raycast line then in our layers let's create a new ray cast layer call it raycast take all our object and apply the layer go to the script and also apply the layer now we can press only on our enemies and nothing else in the scene to make something actually happen get the renderer component of the object and change its color now we can click on our objects and change their color i hope you like this video make sure to subscribe enable notifications and don't forget to like see you in the next one bye
Info
Channel: Nerd Head
Views: 19,848
Rating: undefined out of 5
Keywords: Unity, Programming, Unity3D, how to raycast, how to raycasting, How to unity, mouse raycast, Physics, physics.raycast, physics.raycast unity, raycast, raycast example, raycast tutorial, raycast unity, raycast unity tutorial, raycaster, RaycastHit, raycasting unity, raycasting unity tutorial, raycasts, rays, select, selection, selection using mouse, selection with mouse, tutorial, unity, unity mouse raycast, unity raycast to mouse position, unity raycasting, unity raycust, raycust
Id: aaYfoe9i5lY
Channel Id: undefined
Length: 1min 16sec (76 seconds)
Published: Thu Jan 13 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.