EgonMilanVotrubec

UpdateTimer

Nov 16th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Text;
  3.  
  4. public class UpdateTimer : MonoBehaviour
  5. {
  6.     private StringBuilder output;
  7.  
  8.     public float PauseForTime = 1.0f;
  9.     public bool Record = false;
  10.     public float RecordForTime = 2;
  11.  
  12.     private float hasRunFor = 0;
  13.    
  14.     void Start()
  15.     {
  16.         output = new StringBuilder ( );
  17.     }
  18.    
  19.     void Update()
  20.     {
  21.         if ( hasRunFor == 0 )
  22.             if ( Time.time > PauseForTime ) Record = true;
  23.  
  24.         if ( Record )
  25.         {
  26.             output.AppendLine ( $"Update() at Time.time {Time.time}" );
  27.             hasRunFor += Time.deltaTime;
  28.             if ( hasRunFor >= RecordForTime )
  29.             {
  30.                 Record = false;
  31.                 Debug.Log ( output.ToString() );
  32.             }
  33.         }
  34.     }
  35.  
  36.     private void FixedUpdate ( )
  37.     {
  38.         if ( Record )
  39.             output.AppendLine ( $"FixedUpdate() at Time.time {Time.time}" );
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment