Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Lemo76 · Oct 26, 2014 at 10:47 AM · javascriptgameobjectdestroyfindkeyword

Find Keyword in a Searched GameObject (JS)

Hello, I've currently got a complex turn based game which I working on but I need a quick bit of help with this dilemma.

How do I find and then destroy a gameObject with a keyword in it?

I've got something like:

 if (GameObject.Find(KeywordA in this name of the gameObject)) {
 then go ahead and Destroy(this gameObject);
 }


So if I have many objects named "TestingObject5 Movement=(A different random number)" and a few named "TestingObject4 Movement=(A different random number)", and KeywordA is "TestingObject5", it will destroy all the objects with the name of "TestingObject5 Movement=(A different random number)".

Thanks for the help.

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
0
Best Answer

Answer by Lemo76 · Oct 28, 2014 at 08:59 AM

Ended up using:

 var SceneObj : GameObject [];
 
 function FixedUpdate () {
 SceneObj = FindObjectsOfType(GameObject) as GameObject[];
 }
 
 function CreateTurnObj () {
 for (var i=0; i < AllSceneObj.length; i++){
 if(SceneObj[i].name.Contains("Turn=" + TurnPlace)){
 print (SceneObj[i].name);
 }}}

The one restriction is it can cause lag (i haven't noticed it) if this is used on a scene with a lot of objects.

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
1

Answer by MarksTeq · Oct 26, 2014 at 10:55 AM

You can use tags and then do something like:

   public Object yourObjectNames;
  yourObjectName= GameObject.FindGameObjectsWithTag("Respawn");
  foreach (Object yourObjectName in yourObjectNames) {
             Destroy(yourObjectName,0.0F); 
         }

FindGameObjectsWithTag Manual

Tags Manual Page

Comment
Add comment · Show 2 · 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 Lemo76 · Oct 26, 2014 at 11:16 AM 0
Share

Tags do work, however since in the game I'm instantiating a new set of "TestingObject"'s per turn, it would mean I have to declare up to 99 different tags for each of them.

That's why I'm looking for a way to use the "$$anonymous$$eyword". Thanks.

avatar image MarksTeq · Oct 26, 2014 at 11:28 AM 1
Share

@Lemo76 Here's a similar question that address your problem Finding Game objects with substring

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

28 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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

"GameObject.Find();" not working 2 Answers

Destroy on Collision? 1 Answer

"Destroy Game Object" Not Destroying Game Object 3 Answers

Simple In game search field 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