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 BlackWingsCorp · Feb 19, 2013 at 01:51 PM · javascriptartificial intelligencetechnical

Game not running after script writing

Hey guys how's it going? I wrote a script for a gameobject which is supposed to shoot balls at a certain pace, the console doesn't flash any errors but when I try to run the game the whole engine freezes and it stops responding. Anyone knows what might have caused this? Maybe my laptop needs to cool down or something... anws here's the script: #pragma strict var ball : Rigidbody; var speed : float = 40.0; var canShoot : boolean; var ballNumb : int = 0; function Start () { canShoot = true; }

 function Update () {
 if(canShoot){
 do{
 StartCoroutine("Launcher");}
 while(ballNumb >= 1);
 }
 }
 
 function Launcher (){
 yield new WaitForSeconds(1);
 var newBall : Rigidbody = Instantiate(ball, transform.position, transform.rotation);
 newBall.velocity = transform.forward * speed;
 ballNumb ++;
 yield new WaitForSeconds(0.5);
 Destroy(newBall.gameObject);}
 
Comment
Add comment · Show 1
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 Professor Snake · Feb 19, 2013 at 02:04 PM 0
Share

At the console window, perhaps you have "Error Pause" checked.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Philipp · Feb 19, 2013 at 02:18 PM

In Update, you have a loop that starts a co-routine and then loops if ballNumb is bigger than one. Your co-routine waits for a second, then increases ballNumb. From this point onward, ballNumb will always be >= 1, and the next time Update is called, the loop in Update will launch an infinite number of co-routines and never return, causing Unity to hang.

Comment
Add comment · Show 1 · 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
avatar image BlackWingsCorp · Feb 19, 2013 at 02:31 PM 0
Share

I thought the do-while command was supposed to yield the ball shooting until the current one was shot then destroyed then shoots another 1, any idea how to fix it?

avatar image
1

Answer by Professor Snake · Feb 19, 2013 at 05:04 PM

Set canshoot to false at the beginning of launcher and back to true after the waiting. You are starting that coroutine at every frame the way it is.

Comment
Add comment · Show 1 · 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
avatar image BlackWingsCorp · Feb 20, 2013 at 07:17 AM 0
Share

Yup it worked 10x now onward for the damage scripting

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

11 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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Pain in the ass 2 Answers

Lottery system than can be use once a day 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