Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Stop Unity Wait Time with Button

using UnityEngine;
using Unity;
using System.Collections;

public class testing : MonoBehaviour
{
    // keep a copy of the executing script
    private IEnumerator coroutine;

    // Use this for initialization
    void Start()
    {
        print("Starting " + Time.time);
        coroutine = WaitAndPrint(3.0f);
        StartCoroutine(coroutine);
        print("Done " + Time.time);
    }

    // print to the console every 3 seconds.
    // yield is causing WaitAndPrint to pause every 3 seconds
    public IEnumerator WaitAndPrint(float waitTime)
    {
        while (true)
        {
            yield return new WaitForSeconds(waitTime);
            print("WaitAndPrint " + Time.time);
        }
    }

    void Update()
    {
    //Change Button here
        if (Input.GetKeyDown("space"))
        {
            StopCoroutine(coroutine);
            print("Stopped " + Time.time);
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: C# Payroll 
Csharp :: internet connection sharing 
Csharp :: pem file string reader c# 
Csharp :: c# SQLite execute Command 
Csharp :: ignore warning openxml 
Csharp :: replace update claims c# 
Csharp :: c# project default namespace 
Csharp :: MVC 5 identity SignOut Everywhere for specific user 
Csharp :: spring jar debug level running 
Csharp :: Post and Pre Increment operators in C# 
Csharp :: how to pass id to modal in asp.net mvc 
Csharp :: eager loading singleton c# dependency injection 
Csharp :: short in c# 
Csharp :: .net ssh, wait command execute 
Csharp :: how to close a popup wpf c# on click event 
Csharp :: prometheus add prefix to metrics 
Csharp :: Web forms switch page 
Csharp :: net use error 67 
Csharp :: player ToJson unity 
Csharp :: c# label continue in new line 
Csharp :: eleventy set default layout 
Csharp :: unity remove component 
Csharp :: string methods in c# 
Csharp :: rate game in unity 
Csharp :: how to get day name from datetimepicker in c# 
Csharp :: how to change the width of a panel unity 
Csharp :: how to dynamically load value in startup file in c# 
Csharp :: c# pass mouse events to parent 
Html :: how to link css to html 
Html :: bootstrap cdn link 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =