Using Ray and RaycastHit for User Input
In this Unity 3D tutorial we will be learning how to get user input within our Unity app via RaycastHit. We will do this by using Ray and RaycastHit objects within javascript. It is recommended that you take this course with a friend so you can work together and keep each other accountable. mybringback would also love if you could tweet this course out to your friends, or post on facebook. I wish you the best as a future game developer. -Trav
Video Lesson
Description
In this Unity 3D tutorial for iOS, Android, and Web Deployment, we will get our paddle script up and running, we will also learn a little bit about materials as well. We will move our paddle according to the ray and the ray cast hits that we are familiar with.
Source Code
private var ray : Ray;
private var hit : RaycastHit;
function Start () {
}
function Update () {
if(Input.GetMouseButton(0)){
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit)){
transform.position.x = hit.point.x;
}
}
}
