Question: In the League of Legends, your mouse click on the map where, your hero will go to where you click, then, with u3d how to achieve this small function???
Solution: do radiographic testing. First you have to prepare two things (1): Camera (This is the starting point of the Ray)
(2): "Collision Information" (information used to record the collision point generated by the ray and the object)
Create an empty project in U3d and add a C # script: Raycasttest. Add the two things we just said: "Camera", "Collision info", and initialize them both (the camera will be initialized later)
Hang the script on the camera (Main camera) and use Maincamera to assign the public variable camera
A plane object and a cube object are then created (the object is set to zoom (0.2,0.2,0.2) for reference at the origin of the world coordinate system), and both coordinates are set to (0,0,0)
Continue to write the code in the update:
Now run the project, you can see my test results: At this point I put the mouse on the top of the cube, because cube in the world coordinate system far point, so see the left side of the printed results x,z are 0, and y is greater than 0 (because the cube's top face in the world coordinate system Y axis)
In this, we can get the position information of the point in the world coordinate system that the mouse clicked, and the mouse will see different results in the 1,2,3,4 quadrant I marked.
Outside: Can add a method to facilitate testing, so that only a mouse click, will print a message.
Unity3d Ray Detection