Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1395993 Posts in 67324 Topics- by 60456 Members - Latest Member: Mersy

October 19, 2021, 05:43:48 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)How to put prefabs spawn into an shape area in Unity
Pages: [1]
Print
Author Topic: How to put prefabs spawn into an shape area in Unity  (Read 48 times)
ArtInkStudios
Level 0
**


Art Ink Studio Logo


View Profile WWW
« on: October 09, 2021, 02:42:41 AM »

Hi, I forgot to mention this sooner that I'm new in coding and last time posted on asking for how to spawn position to which I successfully done. But, now need help in wanting the spawning prefabs located within a rectangle area in unity. Here are ideas of want I mean from these web links.  how to create a spawn point within shape area for unity https://www.google.com/search?q=how+to+create+a+spawn+point+within+shape+area+for+unity&tbm=isch&ved=2ahUKEwjis6XB27DzAhUzqHIEHbL2DKkQ2-cCegQIABAA&oq=how+to+create+a+spawn+point+within+shape+area+for+unity&gs_lcp=CgNpbWcQA1Ck58kCWOD1yQJg0v7JAmgAcAB4AIABowGIAfcEkgEDNC4ymAEAoAEBqgELZ3dzLXdpei1pbWfAAQE&sclient=img&ei=3-1aYaLIJbPQytMPsu2zyAo&bih=625&biw=1366&hl=en            
                                                                                                                         
Also here is the random spawn script that I made if needed to apply where for the rectangle script to go to.

public GameObject objectToSpawn;

    public GameObject parent;

    public int numberToSpawn;

    public int limit = 15;

    public float rate;

    float spawnTimer;

    // Start is called before the first frame update

    void Start()

    {

        spawnTimer = rate;

    }

    void Update()

    {

        if (parent.transform.childCount < limit)

        {

            spawnTimer -= Time.deltaTime;

            if (spawnTimer <= 0f)

            {

                for (int i = 0; i < numberToSpawn; i++)

                {

                    Instantiate(objectToSpawn, new Vector3(this.transform.position.x + GetModifier(), this.transform.position.y + GetModifier())

                        , Quaternion.identity, parent.transform);

                }

                spawnTimer = rate;

            }

        }

    }

    float GetModifier()

    {

        float modifier = Random.Range(-10.5f, 10.5f);

        if (Random.Range(0, 2) > 0)

            return -modifier;

        else

            return modifier;

    }

}
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic