public static float deltaTime ;


最後のフレームを完了するのに要した時間(秒)(Read Only)


If you add or subtract to a value every frame chances are you should multiply with Time.deltaTime. When you multiply with Time.deltaTime you essentially express: I want to move this object 10 meters per second instead of 10 meters per frame. Be aware that the deltaTime value is multiplied by the Time.timeScale (that has a default value is 1.0f) before being returned.

When called from inside MonoBehaviour's FixedUpdate, returns the fixed framerate delta time.

Note that you should not rely on Time.deltaTime from inside OnGUI since OnGUI can be called multiple times per frame and deltaTime would hold the same value each call, until next frame where it would be updated again.

using System.Collections.Generic;
using UnityEngine;

public class ExampleClass : MonoBehaviour { public bool halfSpeed; float rotationSpeed = 10f;

List<float> deltaTimes = new List<float>();

void Start() { //If Time.timeScale is set to 0.5f, you should see the deltaTime values half. This is //because deltaTime is multiplied by the timeScale in order to make time dependent //code work as intended. if (halfSpeed) { Time.timeScale = 0.5f; } }

void Update() { LogDeltaTime();


CalculateAndPrintDeltaTime(); }

void LogDeltaTime() { //This adds the latest deltaTime to the list of deltaTimes used to calculate the average. deltaTimes.Add(Time.deltaTime); }

void RotateObject() { //This provides a visual representation of the deltaTime values by rotating the object that this //script is attached to. float eularRotationAngle = rotationSpeed * Time.deltaTime; transform.Rotate(0, 0, eularRotationAngle); }

void CalculateAndPrintDeltaTime() { //This calculates and then prints the average deltaTime whenever the SpaceBar is pressed. if (Input.GetKeyDown(KeyCode.Space)) { float averageDTime = 0; for (int i = 0; i < deltaTimes.Count; i++) { averageDTime += deltaTimes[i]; } averageDTime /= deltaTimes.Count;


Debug.Log(averageDTime); } } }