ThSchm

TickManager

Mar 4th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5.  
  6. public class TickManager : MonoBehaviour
  7. {
  8.     #region Variables
  9.     private static TickManager m_instance;
  10.     public static TickManager Instance
  11.     {
  12.         get { return m_instance ?? ( m_instance = ( new GameObject( "TickManager" ) ).AddComponent<TickManager>() ); }
  13.     }
  14.  
  15.     public event Action lateFixedUpdate;
  16.     #endregion
  17.  
  18.     #region Methods
  19.     // Use to send informationen between scripts
  20.     private void Awake()
  21.     {
  22.         if ( m_instance == null )
  23.         {
  24.             m_instance = this;
  25.         }
  26.         else
  27.         {
  28.             Debug.LogError( "Multiple tick manager scripts found! Make sure to have only ONE manager gameObject in your scene!" );
  29.             Destroy( this );
  30.             return;
  31.         }
  32.         StartCoroutine( FixedTick() );
  33.     }
  34.    
  35.     IEnumerator FixedTick()
  36.     {
  37.         while ( true )
  38.         {
  39.             if ( lateFixedUpdate != null )
  40.             {
  41.                 lateFixedUpdate();
  42.             }
  43.             yield return new WaitForFixedUpdate();
  44.         }
  45.     }
  46.     #endregion
  47. }
Advertisement
Add Comment
Please, Sign In to add comment