• 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 /
  • Help Room /
avatar image
0
Question by Spid3rtech · Jan 03, 2017 at 03:43 AM · gameobjecttaggameobjectstagsgameobject.findgameobject

How to put ".transform" after "GameObject.FindGameObjectsWithTag()"

So I am trying to do this:

 bush = GameObject.FindGameObjectWithTag("Bush").transform;

But with this:

 bush = GameObject.FindGameObjectsWithTag("Bush").transform;

But for some reason, trying to find GameObject*s* with the tag and putting ".transform" after it won't work... I tried removing the ".transform" after it and putting a foreach statement after it, like so:

 foreach (GameObject bushes in bush)
 {
 
 bushes.transform();
 
 }

But it still doesn't work. So I came here, and would appreciate the help. :)

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 hexagonius · Jan 03, 2017 at 10:32 AM 0
Share

what do you mean by doesn't work? the latter is correct except for .transform(). is that an extension method you implemented for gameobjects? what should that line do?

avatar image Spid3rtech hexagonius · Jan 03, 2017 at 08:58 PM 0
Share

Well it does work. The "GameObject.FindGameObjectWithTag("Bush").transform" works. But I need it to recognize Object"S". With an s after it. But it returns an array, so it can't have .transform after it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kiefy · Jan 03, 2017 at 09:37 PM

FindGameObjectsWithTag() returns an array of all objects found.

You would need to use for:

 bushes = GameObject.FindGameObjectsWithTag( "Bush" );

 for ( int i = 0; i < bushes.Length; i++ )
 {
     print( bushes[i].transform )
 }

or foreach:

 bushes = GameObject.FindGameObjectsWithTag( "Bush" );

 foreach ( GameObject bush in bushes )
 {
     print( bush.transform )
 }

or you can gamble on the first one by using:

 bushes = GameObject.FindGameObjectsWithTag( "Bush" );
 print( bushes[0].transform );

or even:

 print( GameObject.FindGameObjectsWithTag( "Bush" )[0].transform )
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

105 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

Related Questions

Unable to use tags on children of a gameobject. 0 Answers

Adding Multiple Tags to a GameObject[] Array 0 Answers

How to change a game objects tag after it has been randomly selected? 0 Answers

CHANGING SCENE AND MAKE A GAME OBJECT ACTIVE THERE 0 Answers

Best alternative for GameObject.Find 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges