Question by
michaelmadnesss · Jun 04, 2021 at 06:40 PM ·
c#timer-scriptrhythm
Making my Timer start with a key press, instead of starting when the game starts.
So I made a timer for my game, It's going to be a Rhythm type game. I'm aiming for adding time so I can add visual events to my song. (for example: if time = 10 then this happens etc etc). the timer wont be visible in the game. I have my timer set up, everything is going well and I know what to do, except for one thing.. My timer starts when the game starts. I want it to start when I press a key, which is when the level starts.
here's my code. feel free to point me in the right direction or make modifications to my code for it to do what I desire.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
public class SongEvents : MonoBehaviour
{
public int CurStep;
public int bpm;
public int beatTempo;
public int StartManager;
public float timeDisplay;
// Start is called before the first frame update
void Start()
{
StartManager = 0;
}
// Update is called once per frame
void Update()
{
if (Input.anyKeyDown)
{
StartManager = 1;
}
if (StartManager == 1)
{
timeDisplay = (Mathf.Round(timeDisplay / 1));
timeDisplay = Time.time;
CurStep = ((int)(timeDisplay / 0.25));
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613034608im_/https://answers.unity.com/themes/thub/images/avi.jpg)