Hi, I new in c#. I would like know how do a variable count for seconds.
Example:
A INT variable is 0. And after 1… and 2, and 3… but, in seconds…
Hi, I new in c#. I would like know how do a variable count for seconds.
Example:
A INT variable is 0. And after 1… and 2, and 3… but, in seconds…
I dont Know C-sharp properly but I’ll try
using UnityEngine;
using System.Collections;
private float TimeInSeconds = 0;
void FixedUpdate(){
CountInSeconds();
}
void CountInSeconds(){
float TimeSubtracted = Time.time;
TimeSubtracted -= Subtractions;
if(TimeSubtracted > 1){
TimeInSeconds++;
float Subtractions+=1;
}
}
I used this once in a game (In Javascript though) so it Should work
I think you are asking to that variable to count seconds elapsed and Here’s a more concise way to do it
using UnityEngine;
using System.Collections;
public class Ticker : MonoBehaviour {
int seconds=0;
void FixedUpdate() {
StartCoroutine(IncrementSeconds());
}
IEnumerator IncrementSeconds() {
yield return new WaitForSeconds(1);
seconds++;
}
}