How to get Mouse Position in 3D and 2D! (Unity Tutorial)

🌍 Get my Complete Courses! ✅
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Games

💬 One of the comments I get a lot is people asking why the code shown in the video isn’t working, and usually the reason is because in the video I showcase some system working in 2D and they’re trying to get it to work in 3D.
It’s pretty simple to get the mouse position in 3D but it is a completely different method compared to 2D.
So here let’s see how both methods work and why they need to be different.
2D: Camera.main.ScreenToWorldPoint(Input.mousePosition);
3D: Physics.Raycast(Camera.main.ScreenToRay(Input.mousePosition, out RaycastHit raycastHit));

🌍 Get Code Monkey on Steam!
👍 Interactive Tutorials, Complete Games and More!

If you have any questions post them in the comments and I’ll do my best to answer them.

🔔 Subscribe for more Unity Tutorials

See you next time!

📍 Support on Patreon
🤖 Join the Community Discord
🎮 Grab the Game Bundle at
📝 Get the Code Monkey Utilities at

#unitytutorial #unity3d #unity2d #unity​ #gamedev​ #indiegame​ #gamedevelopment #madewithunity​ #indiedev​


Hello and Welcome!
I’m your Code Monkey and here you will learn everything about Game Development in Unity using C#.

I’ve been developing games for several years with 8 published games on Steam and now I’m sharing my knowledge to help you on your own game development journey.

I do Unity Tutorials on just about every topic, Unity Tutorials for Beginners and Unity Tutorials for Advanced users.

You can see my games at

– Other great Unity channels:
Brackeys –
Dani –
Jabrils –
BlackthornProd –
Sykoo –
Jason Weimann –
Jonas Tyroller –

– Website:
– Twitter:
– Steam:

Voir sur youtube

La Mer des Sables | Soluce Horizon Forbidden West

Le coin des enfants