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 /
This question was closed Dec 28, 2016 at 06:43 AM by STrehanV for the following reason:

The question is answered.

avatar image
0
Question by STrehanV · Dec 28, 2016 at 05:24 AM · ienumeratorwhile loop

WaitForSeconds For Entering Trigger

 using UnityEngine;
 using System.Collections;
 
 public class TurretShells : MonoBehaviour
 {
     public GameObject turretEmitter;
     public GameObject shell;
     public float shellForce;
 
     void OnTriggerEnter(Collider CharacterController)
     {
         while (true)
         {
             StartCoroutine(haltTime());
             GameObject Temporary_Bullet_Handler;
             Temporary_Bullet_Handler = Instantiate(shell, turretEmitter.transform.position, turretEmitter.transform.rotation) as GameObject;
             Rigidbody Temporary_RigidBody;
             Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent<Rigidbody>();
             Temporary_RigidBody.AddForce(transform.forward * shellForce);
             Destroy(Temporary_Bullet_Handler, 3.0f);
 
         }
     }
 
     IEnumerator haltTime()
     {
         yield return new WaitForSeconds(2);
     }
 }

So what I am trying to do here is have a large cube trigger in front of a turret that activates upon the CharacterController game object entering that trigger. This script is only for getting the shells of the turret to fall out of the barrel. For the actual projectiles, I will be using a Raycast, but that is not what this question is focused on. I know for a fact that the trigger works and starts the process in the script, but the game always freezes from the great number of shells flying out of the barrel (possibly every frame). I decided to implement IEnumerator to add a WaitForSeconds time sleep for the while true while loop found in the script. The problem is that the StartCoroutine(haltTime()); line to execute the IEnumerator method found at the bottom of the script is not taking effect. The game acts the same way as it did without the StartCoroutine line. If I can have any way to adding a very short delay to the while loop, that would make it much better since the shells are automatically deleted after 3 seconds, so overload is not an issue if I can get the shells to come out of the emitter at a slower rate. Thank you.

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

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I make this into a loop with a delay? 0 Answers

IENumerator does not work 0 Answers

IEnumerator keeps saying not all code paths return values 1 Answer

Freezing GameObject in place using collider trigger? 1 Answer

Click two buttons at the same time 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