Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by youffou2012 · Nov 30, 2020 at 03:09 PM · yieldcoroutinesienumeratorsupportguide

WaitUntil doesn't work and the coroutine starts anyways

Hello I've been struggling for hours and I can't fix this problem I'm a newbie and I'm trying to make my script drop EXP after death of a monster But problem is I can't do that at all, I tried using Void Update and failed. And then tried Coroutine which showed progress but problem exp is dropped right away from the start as if the "WaitUntil",which should wait until monsters are dead, isn't there.

Also I'm developing this script further on the CreatorKit Beginner(which is making me struggle a lot)

 using System;
 using CreatorKitCodeInternal;
 using UnityEngine;
 using System.Collections.Generic;
 using System.Collections;
 
 using Random = UnityEngine.Random;
 
 namespace CreatorKitCode 
 {
     public class XPDrop : MonoBehaviour 
     {
     public StatSystem Stats;
      
 
     // Start is called before the first frame update
     void Start()
     {
          StartCoroutine(DropXP());
     }
 
     // Update is called once per frame
     void Update()
     {
         
     }
 
      IEnumerator DropXP()
      {
      yield return new WaitUntil(DEAD);
      XPManager.instance.AddXP(100);
      }
 
      bool DEAD()
      {
        if(Stats.CurrentHealth == 0)
         {
         return true; 
         } 
          else 
        {
          return false; 
          } 
       }
     
      
 }
 }

Please help me cause I'm really sad after spending lots of hours trying to fix it but failing miserably at least if I can't fix this directly, I want to make a new one that drops experience and honestly this is really disappointing.

Comment
Add comment · Show 2
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
avatar image bobbaluba · Nov 30, 2020 at 03:22 PM 1
Share

Are you sure Stats.CurrentHealth is actually 0? Could it be negative? $$anonymous$$ight be safer to do

 bool dead() => Stats.CurrentHealth <= 0;
avatar image PlayCreatively · Nov 30, 2020 at 08:07 PM 0
Share

Well this code should work but I don't know about the rest. Put Debug.Log(Stats.CurrentHealth) in update and make sure it's the correct value.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sacredgeometry · Dec 01, 2020 at 02:38 AM

Have you (immediately) initialised the CurrentHealth field/ property (i.e. to something other than 0 i.e ints default value) ?


If not that will be why. If you have I will change this to a comment.

Comment
Add comment · Share
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

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

147 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

Related Questions

Coroutines not passing yield 1 Answer

Yield return inside a loop slowdown problem 2 Answers

How to use Coroutines in C++/CLI? 1 Answer

Having trouble using coroutines, making unity hang 0 Answers

Change WaitTime, Pause and Resume Coroutines during runtime 2 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