Very simple question
-
So in C#, how can i make an action last for a few seconds?
-
What do you mean by "an action"? A task? An animation?
-
no, like invisibilty
-
@byterail76 You would have to save the end time of the invisibility (start time + how long it lasts), then in a Tick check if the current time is past the end time. Example:
const int INVISIBLE_LENGTH_TIME = 3000; //how long invisibility lasts - 3000 milliseconds bool invisible = false; //invisibility enabled double invisibleEndTime = 0; //when invisibility should end public YourScriptName() { KeyDown += OnKeyDown; Interval = 100; Tick += OnTick; } private void OnKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.T) //start invisibility { Game.Player.Character.IsVisible = false; invisible = true; invisibleEndTime = DateTime.Now.TimeOfDay.TotalMilliseconds + INVISIBLE_LENGTH_TIME; } } private void OnTick(object sender, EventArgs e) { //if current time is greater than end time of inivisibility; time to stop if (invisible && DateTime.Now.TimeOfDay.TotalMilliseconds > invisibleEndTime) { Game.Player.Character.IsVisible = true; invisible = false; invisibleEndTime = 0; } }