How can I mimic KeyCode.X with OnMouseDown

I’m using C# and I have a camera that orbits a target and has a dolly effect to mimic zooming in and out. I can move the camera with my mouse and with the keyboard using Input.GetAxis() but I also have objects in the scene working like a GUI. I can get a script on these objects to zoom the camera. TargetCamera.fieldOfView += increasingValue; But I don’t want to zoom I want to dolly the camera and would prefer to do it in the camera script since it has all the smoothing math on it. So it seems to me I need something in the camera script that calls the keycode.x (x being any key I have assigned to Fire1) when I click on the game object. Or I need a code that calls the fire1 of the camera script when i click on the object, however I don’t know how to do that either.

P.S. The game object I’m clicking on is seen by a secondary “GUICamera” (like a mini map) while the rest of the scene is viewed by the “Main Camera”. It is the “Main Camera” that I want to move when the GUI object is clicked.

P.P.S. is the answers forum bugging out for anyone else?

  1. I think you should make a public GameObject variable of the object: public GameObject targetObject;

  2. Drag your target object onto the public GameObject variable that you made when you are in the inspector.

  3. OnMouseDown, do a physics Raycast from the camera and if it hits the target object… DoSomething()

If you need help with this, let me know