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

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

Channel:
Subscribers:
525,000
Published on ● Video Link: https://www.youtube.com/watch?v=0jTPKz3ga4w



Category:
Tutorial
Duration: 10:20
117,127 views
3,714


๐ŸŒ Get my Complete Courses! โœ… https://unitycodemonkey.com/courses
๐Ÿ‘ Learn to make awesome games step-by-step from start to finish.
๐ŸŽฎ Get my Steam Games https://unitycodemonkey.com/gamebundle

๐Ÿ’ฌ 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!
โœ… https://store.steampowered.com/app/1294220/

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

๐Ÿ”” Subscribe for more Unity Tutorials https://www.youtube.com/channel/UCFK6NCbuCIVzA6Yj1G_ZqCg?sub_confirmation=1

See you next time!

๐Ÿ“ Support on Patreon https://www.patreon.com/unitycodemonkey
๐Ÿค– Join the Community Discord https://discord.gg/eHjUVrm
๐ŸŽฎ Grab the Game Bundle at https://unitycodemonkey.com/gameBundle.php
๐Ÿ“ Get the Code Monkey Utilities at https://unitycodemonkey.com/utils.php

#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 www.endlessloopstudios.com

--------------------------------------------------------------------
- Other great Unity channels:
Brackeys - https://www.youtube.com/user/Brackeys
Dani - https://www.youtube.com/channel/UCIabPXjvT5BVTxRDPCBBOOQ
Jabrils - https://www.youtube.com/channel/UCQALLeQPoZdZC4JNUboVEUg
BlackthornProd - https://www.youtube.com/channel/UC9Z1XWw1kmnvOOFsj6Bzy2g
Sykoo - https://www.youtube.com/user/SykooTV
Jason Weimann - https://www.youtube.com/channel/UCX_b3NNQN5bzExm-22-NVVg
Jonas Tyroller - https://www.youtube.com/channel/UC_p_9arduPuxM8DHTGIuSOg
--------------------------------------------------------------------

- Website: https://unitycodemonkey.com/
- Twitter: https://twitter.com/UnityCodeMonkey
- Steam: https://store.steampowered.com/developer/EndlessLoopStudios







Tags:
unity mouse position to world 3d
unity mouse position
mouse raycast unity
unity cursor position
unity click position
code monkey
physics raycast
unity raycast
unity tutorial
unity game tutorial
unity tutorial for beginners
unity 2d tutorial
unity 3d
unity
game development
game dev
game development unity
unity 2d
unity 3d tutorial
programming
coding
c#
code
software development
learn to code
learn programming
unity tutorials
how to make a game