- Home /
Scripting within a area in the game
Hello,
I need to have a area within the game in which things will randomly instantiate. Is this possible to achieve in the editor? For example to draw some boundaries in an area and apply a script there. Or do I have to manually hardcode the area boundaries I want stuff to instantiate in?
EDIT: I have a terrain in which I want an area that will randomly spawn stuff
Thanks
Please try to find a proper "question title". "Scripting within a area in the game" could be anything and doesn't explain anything.
Even a title of "Spawnarea" would be much more helpful ;)
$$anonymous$$eep in $$anonymous$$d that the questions should be helpful for other people as well. Also A lot people have made TD-games in Unity where you need spawning areas but they won't even look at this question...
Answer by adrenak · Jan 12, 2012 at 10:14 AM
Do it manually. Just put a trigger in the area and some empty game objects in it. When the player enters that area then instantiate the objects in the position of the game objects that you created. Generate some random numbers to decide which positions the objects will instantiated.
$$anonymous$$eep in $$anonymous$$d you don't have to 'hardcode' anything- if you make them public variables, you can still edit them in the inspector.
How do I define the boundaries of that area? Can it be done in the editor? For example is there a tool for 'marking' a section of terrain?
How do I map this area manually then? O_O I guess I need the four X,Y,Z Corners, can you read the XYZ of where a mouse points in unity for example?
you need not consider the 4 coordinates as you said. That way it might get complicated. If the part of the map you are interested in is lets say, square then its fine, but what if its an octagon? Ins$$anonymous$$d make a mesh that resemble the part of the map and make it a trigger and that will work as the boundary.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Set npc to active in same position as previous npc (script not working) 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do i Instantiate a prefab with specific assests included 3 Answers
C# Instantiating a Gameobject with a Flat Sphere Collider 1 Answer