Raycasting: Holding an Object

This one seems pretty easy, but I can’t get my head around it. When casting a ray (on button down) how do you continuously translate an object to the rays position? For example when you move the ray the primitive object will follow the ray’s position.

In pseudo-code so far I have:

  • Create a raycast hit
  • Create a screen point to ray
  • If the ray hits an object, on button down, transform the hit.collider position to the hit.point (where the ray hit the object).

Although even though in the Update method this just translates the object to the ray, however I want it continuously translate to this position, until I let go of the button (on button up). Thought about using invoke repeating, a loop or parenting the object, but still can’t think of a) a way that works or b) the best way to achieve it (and not just hack it in). Any help lol?

Solved this:

Stupidly I was using GetButtonDown, instead of GetButton, so it was just returning the first time the button was pressed, instead of all the frames the button is held down. Don’t be as stupid as me, it’s bad for your health lol :oD