xur_

> module

std::stub::re::unity::time

Unity time control

use std::stub::re::unity::time; feature il2cpp-unity native only

std::stub::re::unity::time reads and writes Unity's Time.timeScale and reads Time.deltaTime and Time.frameCount. Useful for speed hacks and pause functionality.

> functions

# delta() -> f64

The last frame's delta time in seconds, or 0.0 if it can't be read.

# frame_count() -> i64

Unity's frame count, or 0 if it can't be read.

# scale() -> f64

The current time scale (1.0 = normal speed). Returns 1.0 if it can't be read.

# set_scale(scale: f64) -> Result<(), TimeError>

Set the time scale: 0.0 pauses, 2.0 is double speed. Fails with TimeError::SetScale(message) if Unity's setter can't be called.

> types

┌ enum TimeError
TimeError::SetScale(str)

> examples

use std::stub::re::unity::time;

fn stub_main() -> Result<()> {
    // Pause the game
    time::set_scale(0.0)?;

    // Double speed
    time::set_scale(2.0)?;

    // Restore normal speed
    time::set_scale(1.0)?;

    // Read frame timing
    let dt = time::delta();
    Ok(())
}