PLAYER SCRIPT
RAYCASTING | GAME BASED EXAMPLES | COLOR CHANGE VIA MOUSE CLICK
SCRIPT NEEDS TO ACCOMPLISH...
User Input --> Left Mouse Click
Fire Raycast from Mouse position
If collides with object, gather data
If object is a cube, modify color
CODE BREAKDOWN
LINE 11 - 25 ==> If statement that is ran when the user presses the left mouse button
LINE 13 --> Creates a Vector2 type variable to hold the position of the mouse
LINE 14 --> Defines the starting point of the ray [rayOrigin]
LINE 15 --> Structure used to get information back from a raycast collision [RaycastHit]
LINE 18 - 22 ==> If statement that returns true when the ray intersects into any collider [Raycast Declaration]
LINE 20 --> Access the extracted information in
hitInfo
to display the Objects name in the Unity ConsoleLINE 21 --> Goes further into the extracted data in
hitInfo
to change the color of the cube gameobject
Last updated