Please tell me how this can be done (script). I need the camera in unity to move to certain coordinates along the x and y axes (for example, to coordinates 100; 150). I created a dummy, it added a collider. How to do (script, better c #) so that after clicking the coordinates of the camera changed instantly, ie, the camera instantly turned out to be at these coordinates. Thank you in advance.

  • And here object dummy? And then the collider on it? And then the camera, which must move somewhere? Clicking on what is realized? Nothing is clear - Alexey Shimansky
  • We hang a script, for example, on a camera and write in some convenient event transform.position = someObject.transform.position where someObject reference to an object with coordinates - Alexey Shimansky

2 answers 2

Oh ... In general, you need to read the certificate and learn it yourself ... So the points are: 1) You need to create an event for the camera to move (InputMouseButtonDown) reference https://docs.unity3d.com/ScriptReference/Input.GetMouseButtonDown.html 2 ) In this event, you register the following if the script is on the camera Camera C = this as Camera; // should prokanat, well, or skip this line, then this.transform.position ... well, as below. C.transform.position = new Vector3 (100, 0, 150); // here you can play 3) Enjoy life. Well, yes, still need to be done if the script is not on camera, then: If there is a clear idea of ​​public the camera is constant and the object too, then just link them in the inspector. Well, if not, then google, but then immediately everyone wanted)

    1. You create emptyGameObj - an empty object (empty object) and place it in the required coordinates.
    2. in the right place the code attached to the camera

      transform.position = emptyGameObj.transform.position;

    do not forget that you first need to announce the emptyGameObj and find it on the stage. No colliders are needed here.