Quantcast
Channel: Questions in topic: "random spawn"
Viewing all articles
Browse latest Browse all 125

Spawn random prefabs with specific tag and in a specific location.

$
0
0
I have a camera that is in 0 x and y axis and is moving forward to the z axis by itself with a script. I made some prefabs of some models and tagged them in different groups (e.g. "Group1", "Group2", "Group3", etc) so that all the prefabs from group 1 will tile with the prefabs from group 2, all prefabs from group 2 tile with the prefabs of group 3, and the prefabs of group 3 tile with group 1 . So, I need a script that spawns a random prefab from a random group the first time and then it spawns another random prefab from the group that tiles with the prefabs of the group of the spawned prefab. E.g. If the first time a prefab from Group2 is spawned then the next prefab that will spawn will be from Group3, then Group1, then Group2, etc. Note: The first prefab must spawn at (0,0,0) and then each prefab should spawn a (0,0,+variable) where the variable will be added each time a prefab is spawned. E.g. If the variable is 10 then the first prefab will spawn at (0,0,0), the second one at (0,0,10), the third one at (0,0,20), etc. Note 2: When the scene starts I need an X (e.g 10) amount of prefabs to be spawned at once in the way I described above and then each prefab should spawn when it is Y (e.g 100) units near the camera. Also I need the prefabs that the camera has left behind to be destroyed. (I think this is possible by creating a collider for each prefab and destroy them when the camera exits the collision - I need help with the scripting here too). I know that I ask for too much, but I am a complete noob with scripting so any help is much appreciated! Thanks in advance, Michael.

Viewing all articles
Browse latest Browse all 125

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>