Thursday, December 22, 2016

unity - Generate objects on playground on random location


How can I generate an object on my play ground? Note that there are some locations where the new generated item can't be placed.


(Click on image to see the real size)


I was following a tutorial on the site from unity but now I'll add some features by my own. In the tutorial I've done anything whit the 'Navigation'-tab.


(Click on image to see the real size)



For what I need is the blue area on the screenshot above, are good locations to generate a new object on a random place.


However, there are some locations (see red marks on image) where the objects can't be generated because that are the places where the players enemy's spawns.


Can anyone help me to generate the objects?
Thanks in advance.



Answer



You can do this by simple trick.


Place empty GameObjects where you want to spawn your object. Then take an public Array of Transform. Then spawn at any random transform.position in scripts. :)


For clear visuals, place cubes on desired places then delete collider and hide meshes, so it will work as transform only


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...