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 maroltl · Nov 23, 2013 at 02:58 PM · spawning

help with spawning objects

unity always freeze when I prees play. I think there is a problem with for loop but i cant figure it out. heres the code im using. var ball: GameObject;

 var ball: GameObject;
  
 function Start() {
     var ballNum = 3;
     for (var i = 0; i <= ballNum; i++){
         var position = Vector3(Random.Range(1, 10), 0, 0);
         Instantiate(ball, position, Quaternion.identity);
      }
 }
Comment
Add comment · Show 4
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 highpockets · Nov 23, 2013 at 07:05 PM 0
Share

looks like the script should create 4 balls with no problems. Can you post more of your script?

avatar image maroltl · Nov 23, 2013 at 07:12 PM 0
Share

I am using just this script in this project for now

avatar image paulygons · Nov 23, 2013 at 07:25 PM 0
Share

what do you mean by Unity freeze? Do you mean you have no option but to force quit Unity?

avatar image maroltl · Nov 23, 2013 at 07:29 PM 0
Share

yes. it completely stopped working so i had to use ctrl+ alt+del to force quit it. but now it is working when i press play, it just keep spawning balls.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by highpockets · Nov 23, 2013 at 07:15 PM

for (var i : int = 0; i

you didn't declare i correctly, change the for line to what I show above

Comment
Add comment · Show 18 · 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 maroltl · Nov 23, 2013 at 07:23 PM 0
Share

it still doesnt working.Now it keeps spawning balls and dont stop. but i find out that if I press pause button and then play button it works fine.

avatar image highpockets · Nov 23, 2013 at 07:31 PM 0
Share

You sure this script isn't showing the function Update ( ) and not the function Start ( ). It doesn't make sense that it would run through the for loop more than 4 times and therefore keep instantiating more balls. If it keeps instantiating balls even after your game starts, then there must be something happening elsewhere

avatar image Programmer-Tau · Nov 23, 2013 at 07:34 PM 1
Share

Now I'm just totally guessing, but do you maybe have ball set to itself or another object which has the above script?

You'll then have a recursive behavior where each object will create 4 objects, which will each create 4 objects, etc...

avatar image highpockets · Nov 23, 2013 at 07:38 PM 0
Share

ya, you should put this script on an empty game object if it is not already

avatar image highpockets · Nov 23, 2013 at 07:40 PM 0
Share

good point Tau

Show more comments
avatar image
0

Answer by Programmer-Tau · Nov 23, 2013 at 07:06 PM

I don't see anything wrong with the loop itself. Are you assigning something to ball?

Seems like either spamming Debug.Log() or putting break points should give you the answer quickly.

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 maroltl · Nov 23, 2013 at 07:11 PM 0
Share

yes, I have assign object to ball. i just tried with Debug.Log and it works fine.. it logs string 4 times, so I guess there is nothing wrong with loop.

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

18 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

Related Questions

Spawning Objects 1 Answer

Random loot - rarity 3 Answers

error CS1502 and CS1503 1 Answer

Spawning A Grid Of Cubes 2 Answers

How to make the clones of a zombie continue to clone? 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