Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- public class TickManager : MonoBehaviour
- {
- #region Variables
- private static TickManager m_instance;
- public static TickManager Instance
- {
- get { return m_instance ?? ( m_instance = ( new GameObject( "TickManager" ) ).AddComponent<TickManager>() ); }
- }
- public event Action lateFixedUpdate;
- #endregion
- #region Methods
- // Use to send informationen between scripts
- private void Awake()
- {
- if ( m_instance == null )
- {
- m_instance = this;
- }
- else
- {
- Debug.LogError( "Multiple tick manager scripts found! Make sure to have only ONE manager gameObject in your scene!" );
- Destroy( this );
- return;
- }
- StartCoroutine( FixedTick() );
- }
- IEnumerator FixedTick()
- {
- while ( true )
- {
- if ( lateFixedUpdate != null )
- {
- lateFixedUpdate();
- }
- yield return new WaitForFixedUpdate();
- }
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment