Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Der_Kevin · Dec 29, 2015 at 11:24 AM · arraylist

Fill [] array with all available Objects onAwake?

Hey! so i have this multitrack camera with a

 public Transform[] m_Targets;                     // All the targets the camera needs to encompass.
 

which is there to locate all possible targets. at the moment the on Awake part looks like this:

 private void Awake ()
         {
         m_Targets[0] = GameObject.Find("Spawn1").transform;
         m_Targets[1] = GameObject.Find("Spawn2").transform;
         m_Targets[2] = GameObject.Find("Spawn3").transform;
         m_Targets[3] = GameObject.Find("Spawn4").transform;
         }

that means that i assume that i have 4 Palyers (Spawn1-4 are the spawnpoints that the multitrack cam should follow)

what i want to do now, is that the game checks on awake how many Players are in the game. (They get instantiated at the beginning btw with the name Spawn1-4 and the tag "Player". It can also be that only spawn1 and spawn4 are there) and fill them in the array.

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

1 Reply

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

Answer by OncaLupe · Dec 29, 2015 at 10:18 PM

 GameObject[] m_TargetsGO = GameObject.FindGameObjectsWithTag("Player");
 
 m_Targets = new Transform[m_TargetsGO.Length];
 
 for(int i = 0; i < m_TargetsGO.Length; ++i)
 {
     m_Targets[i] = m_TargetsGO[i].transform;
 }

http://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html

Edit: Missed your array was Transforms, added code to handle this since the method returns GameObjects.

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 Der_Kevin · Dec 29, 2015 at 11:33 PM 0
Share

Works perfect! Thanks!

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

36 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

Related Questions

Compare each vector3 from an array to each vector3 in a list and add objects which do not exist into the list 0 Answers

Preventing an array from clearing when playing game. 2 Answers

Find GameObjects With Tag only in a scene. 0 Answers

How to call all instances of a script in a list 0 Answers

Roughly how much processing power is needed to loop through string-Lists/Arrays when loading/saving stored data? 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