- Home /
 
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));
             }
         }
     }
 
              This question has been asked dozens of times. Use google.
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.
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.
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.
Your answer