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 question was closed Jan 08, 2014 at 09:41 PM by TimBorquez for the following reason:

My question and answer were not very good

avatar image
-1
Question by TimBorquez · Mar 25, 2013 at 03:39 PM · instantiateprefabtagspawningsame

Spawning random prefabs with the same tag

im lost, i know it would involve instantiating but i need help

what im trying to do is spawn random prefabs ive made with the tag "toy" when there is a small enough amount of objects tagged with toy

i made an if statement so once theres less than 10 things tagged toy it would make more randomly, but i dont know how

 toyCount = GameObject.FindGameObjectsWithTag ("toy");
 if (toyCount.Length < 10){
      //here i would instantiate "toy" tagged items randomly
 }

thanks

Comment
Add comment · Show 2
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 robertbu · Mar 25, 2013 at 03:49 PM 0
Share

How many? Do you care if you get duplicates of some of them, or must an item from 'toyCount' be unique? How should they be positioned and rotated?

avatar image TimBorquez · Mar 25, 2013 at 05:21 PM 0
Share

i want them to spawn at a single point. I dont care if there are duplicates as long as they are random

2 Replies

  • Sort: 
avatar image
-1
Best Answer

Answer by TimBorquez · Mar 25, 2013 at 06:08 PM

ok i think i may have just discovered that i cant find and spawn things using findallwithtag if they arent in scene

ive now placed my objects in Resource folder

so now im still dealing with the issue of spawning them randomly from that folder

 toyCount = GameObject.FindGameObjectsWithTag ("toy");
     if (toyCount.Length < 10)
     {
         var instance : GameObject = Instantiate(Resources.Load("fake toy"));
     }
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 sdgd · Oct 31, 2013 at 09:30 PM 0
Share

please don't post answer as comment

avatar image
1

Answer by sparkzbarca · Mar 25, 2013 at 04:06 PM

take the prefabs and collect them all up in a list gameobject.findallwithtag

that'll return a list toss that in a newly created variable thats a gameobject list

use random to randomly pick an object.

use it to fill another list this is a list of objects that actually exist

fill that list, while it's size is less than x keep spawning.

as you destroy they'll be respawned. once its size == x stop spawning

Comment
Add comment · Show 6 · 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 TimBorquez · Mar 25, 2013 at 04:19 PM 0
Share

thanks, i dunno exactly how to do everything you said but imma give it a shot

avatar image TimBorquez · Mar 25, 2013 at 05:20 PM 0
Share

ok im still having trouble actually executing this, can someone help

avatar image LexGear · Aug 21, 2013 at 11:41 AM 0
Share

This sounds like what I want.. But itwould have been nice if you used some actual code.

avatar image Erndog2k · Nov 09, 2013 at 09:24 PM 0
Share

thx for posting answer

avatar image Erndog2k · Nov 09, 2013 at 10:30 PM 0
Share

thx for posting answer

avatar image sdgd Erndog2k · Nov 09, 2013 at 10:31 PM 0
Share

please don't post answer as comment

Follow this Question

Answers Answers and Comments

14 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

Related Questions

Is there an easy way to apply the same tag to all children of an object? 4 Answers

How to spawn a new prefab when the last one was destroyed?? 2 Answers

How do you spawn multiple prefabs within a certain distance from each other from one spawn point? 2 Answers

prevent object from falling to the left side when instantiated (spawned) ? 1 Answer

Prefab tag bug 0 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