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 May 28, 2013 at 12:38 AM by robertbu for the following reason:

Duplicate Question

avatar image
0
Question by ic3t3a2000 · May 27, 2013 at 11:58 PM · gameobjectarraylistarrays

How to create an array of Transforms

I have a game object at each corner of my plane. I have an AI script that will send enemy game objects to my player object. When a collision happens I have the enemy stop and then temporarily go towards a corner. But I want the enemy to randomly go to 1 of the four corners.

I know I need to do this by hold the corner game objects in an array and then referencing the transform of one of those objects. However I am very rusty with arrays. Can you give me an example of how I can create an array of gameobject transforms and how I can reference them?

 var corner1 : Transform;
 var corner2 : Transform;
 var corner3 : Transform;
 var corner4 : Transform;
 var cornerOne : GameObject;
 var cornerTwo : GameObject;
 var cornerThree : GameObject;
 var cornerFour : GameObject;
 
 var targetTrans : Transform;
 
 function Start()
 {
 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;
 }
 
 function Update () 
 {
  targetTrans = this.transform;
 }
 
 
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

  • Sort: 
avatar image
3
Best Answer

Answer by Benproductions1 · May 28, 2013 at 12:09 AM

DUPLICATE QUESTION!!
http://answers.unity3d.com/questions/238239/array-of-transforms.html
http://answers.unity3d.com/questions/10986/transform-array-in-javascript.html
http://answers.unity3d.com/questions/252745/storing-transforms-from-objects-in-array.html
http://answers.unity3d.com/questions/14762/array-of-gameobjects.html
http://answers.unity3d.com/questions/331603/array-of-transforms-with-variable.html

The wonders that a google search can do for you!!

Your welcome!
Benproductions1

Comment
Add comment · Show 3 · 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 BritishGuy · Jan 21, 2015 at 01:34 PM 1
Share

Funny how a few years down the line a Google search brings me to this post for me to be diverted to a bunch of other related posts.

avatar image calebebrim · Jun 06, 2015 at 06:39 PM 0
Share

I'm using C#. The provided code does not work for me.

avatar image calebebrim · Jun 06, 2015 at 06:40 PM 1
Share

I also reach this post using GOOGLE!

Follow this Question

Answers Answers and Comments

15 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

Related Questions

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

GameObject to Array/List or whatever fits best 0 Answers

How to select an Game Object from an Item List 0 Answers

Reading all data in the list with duplicate data inside 1 Answer

Cannot find the length of an array 3 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