user14992697
user14992697

Reputation:

C# Unity how could I make something every second?

Could someone tell how could I add to a variable every second 1? Example:

enter image description here

Upvotes: 0

Views: 3847

Answers (1)

rustyBucketBay
rustyBucketBay

Reputation: 4561

You can try coroutines out:

using System.Collections;
using UnityEngine;

public class SecondCounter : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(logEverySecond());
    }

    IEnumerator logEverySecond() {
        while (true) {
            Debug.Log("Tick");
            yield return new WaitForSeconds(1);
        }    
    }
}

Attach this script to gamobject in the scene and see in the console how the ticker logs. Threre you could SimpNum++

Upvotes: 2

Related Questions