Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ninjixfatality · Apr 06, 2018 at 07:02 AM · unity 5ienumeratorminutes

Translating Ienumerator from seconds into minutes?

Hello everyone im fairly new to C# and unsure how to translate this into my script. I have a bird script that hovers over the player. I have everything set in float seconds but I want that my FadeIn() function and Ienumerator GameReset() use 1minute instead. This will help because I want players to have some time to shoot down the bird without having the issue of the game automatically resetting in a matter of seconds.The point of my game is that if players take too long the bird will attack them causing a reset window to appear

 public float waitTime = 10.0f;
 public float fadeTime = 3.0f;
 public float betweenFadesTime = 2.0f;

 // Flag to determine whether or not the player may respond.
 public bool canRespond = false;

 // Flag to determine if the player has responded within the wait time.
 public bool hasResponded = false;

 public GameObject enemy;

 void Start()
 { StartCoroutine(EnemyFadeIn(fadeTime, betweenFadesTime, waitTime)); }

 void Update() {
     if ((Input.GetKeyDown(KeyCode.S)) && (canRespond))
     { hasResponded = true; }
 }

 IEnumerator EnemyFadeIn(float timeToFade, float timeBetweenFades, float timeToWait) {
     Debug.Log("An Enemy Is Fading In");
     // Simulating Fade In Time.
     yield return new WaitForSeconds(timeToFade);
     // Fade in
      iTween.FadeTo(enemy, 1, 1);
      Invoke("SetMaterialOpaque", 1f);
     Debug.Log("An Enemy Has Appeared");

     yield return ListenForInput(timeToFade, timeBetweenFades, timeToWait);
 }

 IEnumerator EnemyFadeOut(float timeToFade, float timeBetweenFades, float timeToWait) {
     Debug.Log("An Enemy Is Fading Away");
     // Simulating Fade Out Time.
     yield return new WaitForSeconds(timeToFade);
     // Fade out
      SetMaterialTransparent();
      iTween.FadeTo(enemy, 0, 1);
     Debug.Log("An Enemy Has Departed");
     // Simulating Time Between Fades.
     yield return new WaitForSeconds(timeBetweenFades);

     yield return EnemyFadeIn(timeToFade, timeBetweenFades, timeToWait);
 }

 // Responsible for reacting to the 'S' key input.
 IEnumerator ListenForInput(float timeToFade, float timeBetweenFades, float timeToWait) {
     canRespond = true;
     Debug.Log("Press the 'S' Key to Destroy the Enemy!");
     float startTime = Time.time;

     // Check every 0.25 seconds to see if the S key was pressed.
     while (Time.time < (startTime + timeToWait)) {
         if (hasResponded) {
             Debug.Log("The 'S' Key was Pressed!");
             hasResponded = false;
             canRespond = false;
             yield return EnemyFadeOut(timeToFade, timeBetweenFades, timeToWait);
         }
         yield return new WaitForSeconds(0.25f);
     }

     Debug.Log("The 'S' Key was not Pressed!");
     canRespond = false;
     yield return ResetGame();
 }

 IEnumerator ResetGame() {
     Debug.Log("Game is Performing a Reset");
     Simulating Game Reset Time.
     yield return new WaitForSeconds(30);
     Debug.Log("Game has Restarted. End of Coroutine!");
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

208 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I use the IEnumerator in my example? (If yes, how?) 0 Answers

The right way using Coroutine and Ienumerator 0 Answers

How do I get an entity's IEnumerator to pause when the entity is seen? 0 Answers

Unable to find image effects in unity 5.6.1(f1) 0 Answers

Assets/Scripts/RespawnMenu.js(8,20): BCE0018: The name 'MouseLook' does not denote a valid type ('not found'). Did you mean 'UnityStandardAssets.Characters.FirstPerson.MouseLook'? After Upgrading to Unity 5 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges