Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mmertbbulut · Nov 30, 2021 at 04:21 PM · arrayscript.

Spawn Point Repeating

Hello Unity community, i make this car spawn script. I have 2 problem about this script. 1- When i run game its normal working and spawn 6 car ( 3 Left side 3 right side) but when i trigger car spawner its spawn 12 car not 6 car. I cant fix it. 2- Sometimes cars spawn same spawn point how i can make it non repeating ?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System.Linq;
 
 public class SpawnSystem : MonoBehaviour
 {
     public GameObject[] cars;
     public Transform[] leftSpawnPoint;
     public Transform[] rightSpawnPoint;
 
     void Start()
     {
 
         for (int i = 0; i < 3; i++)
         {
 
             Instantiate(cars[Random.Range(0, cars.Length)], leftSpawnPoint[Random.Range(0, leftSpawnPoint.Length)].position, Quaternion.Euler(0, 180, 0));
             Instantiate(cars[Random.Range(0, cars.Length)], rightSpawnPoint[Random.Range(0, rightSpawnPoint.Length)].position, Quaternion.identity);
         }
     }
 
     public void SpawnCar()
     {
         for (int i = 0; i < 3; i++)
         {
             Instantiate(cars[Random.Range(0, cars.Length)], leftSpawnPoint[Random.Range(0, leftSpawnPoint.Length)].position, Quaternion.Euler(0, 180, 0));
 
             Instantiate(cars[Random.Range(0, cars.Length)], rightSpawnPoint[Random.Range(0, rightSpawnPoint.Length)].position, Quaternion.identity);
 
         }
     }
 }


Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MilitaryG · Nov 30, 2021 at 07:38 PM 0
Share

Delete everything in Start and make it like this:

 void Start(){
     SpawnCar();
 }

Also don't call spawnCar() If start has spawned it

So try and comment Start()

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mmertbbulut · Nov 30, 2021 at 09:40 PM

Okey i change it. But its still spawn 6 car first and 12 car more when enter trigger. alt text

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System.Linq;
 
 public class SpawnSystem : MonoBehaviour
 {
     public GameObject[] cars;
     public Transform[] leftSpawnPoint;
     public Transform[] rightSpawnPoint;
 
     void Start()
     {
 
         SpawnCar();
     }
 
     public void SpawnCar()
     {
         for (int i = 0; i < 3; i++)
         {
             Instantiate(cars[Random.Range(0, cars.Length)], leftSpawnPoint[Random.Range(0, leftSpawnPoint.Length)].position, Quaternion.Euler(0, 180, 0));
 
             Instantiate(cars[Random.Range(0, cars.Length)], rightSpawnPoint[Random.Range(0, rightSpawnPoint.Length)].position, Quaternion.identity);
 
         }
     }
 }



screenshot-4.png (11.1 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MilitaryG · Dec 01, 2021 at 12:14 AM 0
Share

Well as i said you are calling the function some where else to.

And don't post coments as answers.

Please convert it to comment.

avatar image
0

Answer by luvm1n3craft · Dec 01, 2021 at 02:37 AM

Your spawn points are repeating because you're choosing a random spawn point every time you instantiate a new car. Try this:

  public void SpawnCar()
  {
      for (int i = 0; i < 3; i++)
      {
          Instantiate(cars[Random.Range(0, cars.Length)], leftSpawnPoint[Random.Range(0, leftSpawnPoint.Length)].position, Quaternion.Euler(0, 180, 0));
 
          Instantiate(cars[Random.Range(0, cars.Length)], rightSpawnPoint[Random.Range(0, rightSpawnPoint.Length)].position, Quaternion.identity);
 
      }
  }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mmertbbulut · Dec 01, 2021 at 03:33 AM 0
Share

This is same as $$anonymous$$e ? nothing different.

avatar image
0

Answer by mmertbbulut · Dec 01, 2021 at 01:43 AM

Okey i fix my problem when i remove my car collider its fixed but now i need to make my spawns no repeate. How i can make it ?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

178 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I need some help accessing an array from another script 1 Answer

Array for items (Inventory) Not Working 1 Answer

How do I make an array from text objects and get them to instantiate randomly? 1 Answer

How to hide/unhide an array of objects with a mouse click. 0 Answers

List of scripts? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges