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 /
avatar image
0
Question by manaslegodesigns · Dec 01, 2017 at 05:34 AM · instantiatecubegeneration

Generate cubes in 5 areas

i have a plane surface with 5 vector3 for a position on the surface for a cube.When the game starts the cube move towards me with a randomly generated position of the 5 vector 3's. i want that when the cube's position is between 2 points on the x surface , i want the cube to Instanciate and again pick one of the 5 positions and again start moving towards me and this should continue in a cycle.

This is the code i am using to pick one of the 5 positions.

 public Vector3 Gen(Vector3 sam)
 {
     int posStart = Random.Range(0, 5);
     if (posStart == 0)
     {

         sam = one;
     }
     else if (posStart == 1)
     {

         sam = two;
     }
     else if (posStart == 2)
     {

         sam = three;
     }
     else if (posStart == 3)
     {
         sam = four;
     }
     else if (posStart == 4)
     {
         sam = five;
     }
     return sam;
 }


i can move the cube, no problem there

This is the code for instanciation

if (enemy.transform.position.x >= 1.49 && enemy.transform.position.x <= 1.5) { Instantiate(enemy);

     }



This works some times and fails the other times. Some times it does this process 2-4 times and then it just stops generating

Any help would definitely be appreciated. Thanks!!

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

1 Reply

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

Answer by Darkforge317 · Dec 01, 2017 at 06:11 AM

Your cube's speed may be too fast for a range of 0.1 units. You're checking if it's position is between 1.49 and 1.50. It's a very small range.

If your cube moves too fast then it's position may go from 1.48 to 1.51. It all depends on the speed.

Other than that, your code looks completely fine to me, but although we're only seeing a small portion of it so there may be a problem elsewhere.

Comment
Add comment · Show 7 · 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 manaslegodesigns · Dec 01, 2017 at 06:17 AM 0
Share

see if the cube is moving too fast then how come some times it IS generating the cubes and sometimes it is not Anyway thanks for the reply,but see if you can help me Thanks

avatar image Darkforge317 manaslegodesigns · Dec 01, 2017 at 06:33 AM 0
Share

Since you're calling this method from the update method (I'm assu$$anonymous$$g you are) then each frame is completed either faster or slower than the previous one. No guarantees on anything when it comes to frame-rate.

Sorry if you don't like my answer... But that's honestly what I think the problem is, because I can't see your scene and I've only seen a small portion of your code.

avatar image manaslegodesigns Darkforge317 · Dec 01, 2017 at 07:03 AM 0
Share

Yeah actually that might be the problem See basically i want the cube to be instanciated only once in any range between 1.45-1.5 See if you can help me further Thanks for any reply

Show more comments

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

91 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

Related Questions

How to instantiate a custom sized object? 1 Answer

Problem with repeating objects in array when already in the array 0 Answers

Place cubes? problem with my script :S 1 Answer

Block ground generation 2 Answers

Unity not Instantiating Prefabs Properly 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