Answer the question
In order to leave comments, you need to log in
Object Reference not set to an instance of an object. What to do?
There is a function:
public static void CreatePNG(CommandArgs args)
{
try
{
GameObject _cam = new GameObject();
var cam = UnityEngine.Object.Instantiate(_cam, new Vector3(args.sender.position.x + 10f, args.sender.position.y, args.sender.position.z), args.sender.rotation);
((GameObject)cam).camera.aspect = 1.0f;
RenderTexture tempRT = new RenderTexture(512, 512, 24);
((GameObject)cam).camera.targetTexture = tempRT;
((GameObject)cam).camera.Render();
RenderTexture.active = tempRT;
Texture2D virtualPhoto = new Texture2D(512, 512, TextureFormat.RGB24, false);
virtualPhoto.ReadPixels(new Rect(0, 0, 512, 512), 0, 0);
RenderTexture.active = null;
((GameObject)cam).camera.targetTexture = null;
byte[] bytes = virtualPhoto.EncodeToPNG();
StreamWriter streamWriter = new StreamWriter("Unturned_Data/Managed/picture.png", true);
streamWriter.Write(bytes);
streamWriter.Close();
Reference.Tell(args.sender.networkPlayer, "Successfully created Picture!");
UnityEngine.Object.DestroyObject(cam);
}
catch (Exception err)
{
Reference.Tell(args.sender.networkPlayer, $"Err: {err.Message}");
}
}
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