Greetings.
My tester wanted the ability to step frame by frame on the actual device (Android/iOS) cause it would help catch bugs.
I know you could easily build your game with single frame stepping in mind and it would work but I’m in a point where it’s hard to add that feature in, I would have to mold everything to play nicely with it.
I thought it would be nice to have the built-in Editor Pause/Step which works perfectly. I saw that the functions are in EditorApplication.Pause() and EditorApplication.Step() but obviously that’s editor only.
Is there anyway to get that same functionality off of Unity’s runtime libraries?
Thanks.
EDIT: Thanks to @gorsefan here’s the final code I used with the timeScale, works very well as long as you’re Time.deltaTime in your game and not an unscaled deltaTime.
Just attach this script to a GameObject and call Toggle (turns it on/off) or Step to step a single frame.
using UnityEngine;
using System.Collections;
public class FrameStepper : MonoBehaviour
{
bool IsOn;
bool IsStepping;
public void Toggle()
{
IsOn = !IsOn;
}
public void Step()
{
IsStepping = true;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.S))
{
Toggle();
}
else if (Input.GetKeyDown(KeyCode.N))
{
Step();
}
if (IsStepping)
{
Time.timeScale = 1;
IsStepping = false;
}
else
{
Time.timeScale = IsOn ? 0 : 1;
}
}
}