Мне нужно повернуть объект камеры в сторону объекта Vector3, так чтобы камера смотрела на него, как это можно осуществить ?
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;
}
}