- Home /
Other
Instantiate GameObjects inside a collider
Hi!
I'm trying to instantiate gameobjects in an area. This area is a mesh collider, so I was wondering if there is a way to instantiate gameobjects inside the collider so there's no possibility to find an instantiated gameobject outside the collider's bounds.
Answer by yomanz453141 · Jun 16, 2019 at 08:18 AM
GameObject area;
Public GameObject item;
void start()
{
area = GameObject.Find("area");
Instantiate (item, area.transform.position, transform.rotation)
}
Do ensure you have the item prefab alloted to the item gameobject. This piece of code will instantiate the item gameobject at the position of the area gameobject, i. e., Within its mesh renderer provided the item gameobject is obviously smaller in scale. @ratchetunity
Hi @yomanz453141 I want to spawn several gameobjects (let's say 300) inside the collider so each one has a different position but all the spawned gameobjects remain inside the collider