Click on object to assign a var to another object?

Okay, so basically what I’m trying to do is click on a object and get it assigned as a var. If I click on another one, I want it to be the var instead of the one I previously clicked. How can I do this?

  1. In your Update handler, check for mouse down
  2. When mouse is down, get the mouse position from Input
  3. COnvert the mosue position to a pick ray using Camera.main.ScreenPointToRay
  4. Cast the ray and find the object it intersects using Physics.Raycast
  5. Assign that object to your variable