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
1
Question by freshgamer10 · Sep 17, 2013 at 03:59 PM · randomspawninglooting

Random Loot / Weapon Spawning

Hey,

I am currently working on my game and I wanted to implement a feature where you never know where Loot is going to spawn. You also will not know where the buildings of the game will spawn, but that's something I have already implemented. The problem is, that I do want to spawn the loot on top of a collider and at a random position. The buildings also have a random position which makes it hard to get their exact spot. Right now, there are a few weapons I have implemented, I want to spawn a random amount of weapons at a random spot in each building. I made a script, but it does not really work at all. I do know why, but I have quite a complicated approach, so I was hoping for a better solution. You can find my code below, it would be much appreciated if someone could help me. Thanks in advance :)

 void WeaponSpawn()
     {
         int[] WeaponsToSpawnInBuilding = new int[Buildings.Length];
 
         for (int i = 0; i < WeaponsToSpawnInBuilding.Length; i++)
             WeaponsToSpawnInBuilding[i] = Random.Range(0, 3);
 
         for (int i = 0; i < Buildings.Length; i++)
         {
             for (int j = 0; j < WeaponsToSpawnInBuilding[i]; j++)
             {
                 Weapons[j].localPosition = new Vector3(BuildingSpawnAreas[i].position.x + Random.Range(0, 10), Weapons[j].position.y, BuildingSpawnAreas[i].position.z + Random.Range(0, 10));
             }
         }
     }
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 flaviusxvii · Sep 17, 2013 at 05:29 PM 0
Share

This question has been asked dozens of times. Use google.

avatar image freshgamer10 · Sep 17, 2013 at 07:41 PM 0
Share

I fixed it already, but I was actually planning on detecting the collider and placing the Game Object accordingly. Never $$anonymous$$d though, I fixed it anyways.

avatar image Lo0NuhtiK · Sep 17, 2013 at 10:28 PM 0
Share

If you fixed or figured out whatever you were asking, ins$$anonymous$$d of saying "never $$anonymous$$d, I fixed it myself" , you should post your solution for others that may have the same question.

avatar image freshgamer10 · Sep 18, 2013 at 06:28 PM 0
Share

Okay, I am sorry. I was going to do that but I can just work on the weekends and that was just one day where I could work for a few hours. I was planning on posting the solution, but my code is quite specific. I will add it to the post once I get home, so probably Saturday.

0 Replies

· Add your reply
  • Sort: 

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

17 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

Related Questions

Finding the minimum distance between randomly spawned objects in a 9 x 9 grid. 1 Answer

Random map generation and random spawn points. 0 Answers

Enemies randomly appearing behind objects 1 Answer

How to add randomness in the following code snippet? 0 Answers

Logical Error In Spawn Counter (Javascript) 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