10 – User Input with Ray and Raycasthit Unity 3D Tutorial

This entry is part 10 of 13 in the series Unity 3D

User Input with Ray and Raycasthit Unity 3D TutorialUsing 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


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 () {
		ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		if(Physics.Raycast(ray, hit)){
			transform.position.x = hit.point.x;


Previous Lesson
Next Lesson

Author: trav

I'm just an average guy that love programming.

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>