- Home /
Question by
ogasa · Aug 24, 2018 at 02:59 AM ·
capturecapturescreenshot
CaptureScreenshot & physical simulation
When "CaptureScreenshot" is used, the result of the physical simulation changes. Is there a way to avoid this? I attach the following script to the Main Camera.
using UnityEngine;
using System.Collections;
public class ScreenRecorder : MonoBehaviour
{
public int framerate = 30;
public int superSize;
public bool autoRecord;
public int rate30 = 1;
int frameCount;
bool recording;
void Start ()
{
if (autoRecord) StartRecording ();
}
void StartRecording ()
{
System.IO.Directory.CreateDirectory ("Capture");
Time.captureFramerate = framerate;
frameCount = -1;
recording = true;
}
void Update ()
{
if (recording)
{
if (Input.GetMouseButtonDown (0))
{
//recording = false;
//enabled = false;
}
else
{
if (frameCount > 0 && frameCount % rate30 == 0)
{
var name = "Capture/frame" + (frameCount/rate30).ToString ("0000") + ".png";
ScreenCapture.CaptureScreenshot (name, superSize);
}
frameCount++;
if (frameCount > 0 && frameCount % 30 == 0)
{
Debug.Log ((frameCount / 30).ToString() + " seconds elapsed.");
}
}
}
}
void OnGUI ()
{
if (!recording && GUI.Button (new Rect (0, 0, 200, 50), "Start Recording"))
{
StartRecording ();
Debug.Log ("Click Game View to stop recording.");
}
}
}
Comment
It looks like you're trying to record video and Unity doesn't have a good built-in solution for that. Try NatCorder. It works well for me.