Hello, I’d like to increase a variable’s value by one each time, I’ve looked everywhere and I’ve only seen it in JS but I can’t seem to find any for C# and I can’t translate JS-C# very well. If someone could teach me how to increase a value by one each second or tell me how to do it that’d be great!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class random : MonoBehaviour {
float foo;
float valueToIncreaseEverySec;
void Start ()
{
}
void Update()
{
foo += valueToIncreaseEverySec * Time.deltaTime;
}
}
alright I’ll explain what this does, the variable foo is just any old variable and the variable valueToIncreaseEverySec is the value you want foo to increase by, and in the update method the line is essentially saying, plus valueToIncrease * Time.deltaTime to foo, Time.deltaTime is the time between each frame you need this so it can plus the value according to unity, without things become crazy.