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 /
This question was closed Sep 27, 2016 at 06:40 PM by Vylax for the following reason:

Find the solution somewhere else

avatar image
0
Question by Vylax · Sep 09, 2016 at 05:41 PM · destroyrandomyield waitforseconds

Ground cycle destroy,Ground destruction problem

Hi, I'm making a roll a ball game to find my level cuz I didn't used unity for a long.

I made a 15x15 ground separated in 15x15 (225) cubes.

I want one of them get selected every 5 sec then color it red for 0.5 sec and then destroy it.

My problem is that I want the cubes to disapear one by one evry 5 sec and they all disapear in a few seconds.

Youtube video showing what's happening.

Here's my script:

 #pragma strict
 
 var RN : int = -1;
 var groundPart : GameObject[];
 var destroyCooldown : int = 5;
 var timer : float = 0;
 var groundIsDestroyed : boolean = true;
 
 function Start () {
     groundPart = GameObject.FindGameObjectsWithTag("Ground");
 }
 
 function Update () {
     if(groundIsDestroyed == true) {
         Cooldown();
     }
 }
 
 function Cooldown () {
     yield WaitForSeconds(destroyCooldown);
     groundIsDestroyed = false;
     DestroyGround();
 }
 
 function DestroyGround () {
     if(groundIsDestroyed == false) {
     RN = Random.Range(0, groundPart.length);
     if(RN <= groundPart.length) {
         groundPart[RN].GetComponent(MeshRenderer).material.color = Color.red;
         yield WaitForSeconds(0.5);
         Destroy(groundPart[RN]);
     }
     RN = -1;
     groundIsDestroyed = true;
     }
 }


Thank you for ur help.

Comment
Add comment · Show 10
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 Sergio7888 · Sep 10, 2016 at 08:33 AM 0
Share

It disappear because it was destroyed, try replace the destroy with SetActive(bool value).

avatar image Vylax Sergio7888 · Sep 10, 2016 at 02:40 PM 0
Share

It don't change anything...

$$anonymous$$y problem is that I want the cubes to disapear one by one evry 5 sec and they all disapear in a few seconds.

avatar image Sergio7888 Vylax · Sep 10, 2016 at 02:49 PM 0
Share

every 5 sec or every half sec (0.5)? if need change the color at 0.5 and destroy at 5 then divide the code in 2 coroutines one for color change and other for destroy.
If you need change the color and after 5 seconds destroy, after 0.5 repeat the process you will need 2 WaitForSeconds in your code one of 5 after change the color and other of 0.5 before the end of loop.

avatar image Sergio7888 · Sep 10, 2016 at 03:00 PM 1
Share

Try it:


function Start () {
     groundPart = GameObject.FindGameObjectsWithTag("Ground");
     StartCoroutine(DestroyGround()); 
 }
 function DestroyGround () {
    while(true){
       RN = Random.Range(0, groundPart.length);
       if(RN ]]]
avatar image Vylax Sergio7888 · Sep 10, 2016 at 04:11 PM 0
Share

Work perfectly thank you so much !

avatar image Vylax Sergio7888 · Sep 10, 2016 at 06:01 PM 0
Share

I'm sorry but I still have a problem, it work perfectly but when groundPart.length reach 0 the unity freeze and do not responce. I want to know how I shoul use StopCoroutine(xxx()); this don't work:

  function Update () {
      if(groundPart.Length == 0) {
          StopCoroutine(DestroyGround());
      }
  }
avatar image Sergio7888 Vylax · Sep 10, 2016 at 07:36 PM 0
Share
 try use:
 
 Coroutine corr;
 
 corr=   StartCoroutine(DestroyGround()); 
 
 StopCoroutine(corr);
Show more comments

1 Reply

  • Sort: 
avatar image
0

Answer by doublemax · Sep 10, 2016 at 02:58 PM

WaitForSeconds() etc. only work in Coroutines(). You need to call those functions with StartCoroutine().

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

Follow this Question

Answers Answers and Comments

60 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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Destroy bullet on random collision 2 Answers

Edit - Code isolation using random ID numbers C# 1 Answer

Don't destroy on load not working? 4 Answers

How can i destroy a game object? 1 Answer


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