Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question