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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by el-santia93 · Aug 29, 2013 at 11:28 AM · instantiaterandom

Making more than one item appear on a chess board

hi,am making a game where stuff appears on a chess board and the player clicks etc etc.Currently i have one item appearing on a random position on the board but i don't know how to make more than one item appear. Someone please help

 var cube1:GameObject;
 var cube2:GameObject;
 
 var clone:GameObject;
 var obj:GameObject[];
 var spawnPoints:GameObject[];
 
 
 function Start () {
 spawnPoints=GameObject.FindGameObjectsWithTag("spawn");
 Call();
 
 }
 
 function Update () {
 
 }
 function Call(){
 yield WaitForSeconds(2);
 var randomPosition=Random.Range(0,spawnPoints.Length);
 
 var randomObj=Random.Range(0,obj.length);
 //spawnPoints.RemoveAt(randomPosition);
 
 
 Debug.Log(randomPosition);
 clone=Instantiate(obj[randomObj],spawnPoints[randomPosition].transform.position,Quaternion.Euler(0,180,0));
 clone.name="Object";
 
 //Destroy(obj[randomObj]);
 //obj.RemoveAt(randomObj);
 
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ArkaneX · Aug 29, 2013 at 12:04 PM

You can change Call method to include count parameter (number of objects you want to spawn):

 function Call(count : int){
     yield WaitForSeconds(2);
     for(var i : int = 0; i<count; i++) {
         // whole random and instantiate stuff for single object
     }
 }

And then for example execute Call(5). If you need to introduce additional delay between spawning objects, then add additional yield inside the for loop.

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
avatar image
0

Answer by EBR · Aug 29, 2013 at 12:35 PM

You could add a for loop so that it instantiates a chess piece for every x amount.

var inst_amount : int = 1; //The amount of chess pieces you want to instantiate

for(int i = 0; i <= inst_amount - 1; i++) { *instantiate chess piece here* }

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

18 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

Related Questions

How to access property of a prefab before Instantiating. 1 Answer

Make sure objects are not instantiated on each other 2 Answers

C# Spawn Random Object, at Random 2D Location 2 Answers

Drop item from airplane 1 Answer

How to instantiate 2D object at fixed location? 1 Answer


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