N
N
NeoLight32020-09-11 19:09:48
C++ / C#
NeoLight3, 2020-09-11 19:09:48

How to rotate Quaternion angle towards Vector3 object?

I need to rotate the camera object towards the Vector3 object so that the camera is looking at it, how can this be done?

public static byte[] renderPicture(Quaternion rotation, Vector3 position)
        {
      try
      {
        GameObject camera = new GameObject("camera");
        GameObject lightGameObject = new GameObject("The Light");
        GameObject _camera = (GameObject)UnityEngine.Object.Instantiate(camera, position, rotation);
        Light lightComp = lightGameObject.AddComponent<Light>();
        Camera _spycam = _camera.AddComponent<Camera>();
        Camera spycam = _camera.GetComponent<Camera>();
        lightComp.range = 100;
        lightComp.color = Color.white;
        lightGameObject.transform.position = position;
        lightGameObject.transform.rotation = rotation;
        RenderTexture tempRT = new RenderTexture(2000, 1200, 32);
        spycam.targetTexture = tempRT;
        spycam.Render();
        RenderTexture.active = tempRT;
        Texture2D virtualPhoto = new Texture2D(2000, 1200, TextureFormat.RGB24, false);
        virtualPhoto.ReadPixels(new Rect(0, 0, 2000, 1200), 0, 0);
        RenderTexture.active = null;
        spycam.targetTexture = null;
        byte[] bytes = virtualPhoto.EncodeToPNG();
        UnityEngine.Object.Destroy(_camera);
        UnityEngine.Object.Destroy(lightComp);
        return bytes;
      }
      catch (Exception ex)
      {
        return null;
      }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Herman Coffman, 2020-09-13
@NeoLight3

transform.LookAt()
What are you, you need to google )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question