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 /
avatar image
0
Question by ic3t3a2000 · May 28, 2013 at 12:55 AM · gameobjectarrayarrays

Transform array help

My original post was closed before I could ask this so I am creating a new one. http://answers.unity3d.com/questions/464315/how-to-create-an-array-of-transforms.html

I tried using several of the suggestions and am having issues. Any insight in to what I am doing wrong would be greatly appreciated.

I tried using:

var _targets : Transform[];

But when I tried to drag and drop my corner game objects on to the elements in the inspector it will not take them. In other words I have the AI script on my enemy game object prefab. It has the AI script on it which has the variable _targets. I adjust the target size to 4. Then try to drag and drop the corner gameobjects on it.

How do I drag and drop the transform of a game object on to this in the inspector?

I also tried to do this manually in the script. I tried using.

 var balls : ArrayList;
 
 function Start()
 {
     balls = new ArrayList();
 }
 
 function Update()
 {
      cornerOne= GameObject.FindWithTag ("corner1");
     cornerTwo= GameObject.FindWithTag ("corner2");
     cornerThree= GameObject.FindWithTag ("corner3");
     cornerFour= GameObject.FindWithTag ("corner4");
     corner1 = cornerOne.transform;
     corner2 = cornerTwo.transform;
     corner3 = cornerThree.transform;
     corner4 = cornerFour.transform;
     balls.Add(corner1);
     balls.Add(corner2);
     balls.Add(corner3);
     balls.Add(corner4);
 }


However when I try to print whats in my array called balls. It just says "System.Collections.ArrayList". It does not list any of the transforms I added to the array.

I am sure I have the context wrong but I am at a loss for where I am going wrong..

Comment
Add comment · Show 1
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 Benproductions1 · May 28, 2013 at 02:21 AM 0
Share

Have you tried ragging it on the name, not the length variable? Because that definitely works!!!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · May 28, 2013 at 02:48 AM

Assuming you know the size ahead of time the size will be 4, you can do:

 private var balls : Transform[];
  
 function Start() {
     balls = new Transform[4];
 }
  
 function Update() {
     balls[0] = GameObject.FindWithTag ("corner1").transform;
     balls[1] = GameObject.FindWithTag ("corner2").transform;
     balls[2] = GameObject.FindWithTag ("corner3").transform;
     balls[3] = GameObject.FindWithTag ("corner4").transform;
 }

If the number of entries is variable, consider using a List (Generic), not an ArrayList.

Reference on array types:

http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F

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

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

Instantiate from array into array? 2 Answers

How To Get A Reference To All Nearby GameObjects? 1 Answer

Problems with Arrays 2 Answers

Array.length edited using scripts 2 Answers

How to Narrow Down an Array casted from FindObjectsOfType 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