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 Pauls · Nov 27, 2012 at 03:45 AM · arraylistasset

Create Array of Transforms and Detect Distance

Hi,

i don't understand the doc, i would like to use an ArrayUtility (http://docs.unity3d.com/Documentation/ScriptReference/ArrayUtility.html) function : IndexOf, and they say : To use it you have to place your script in Assets/Editor inside your project folder.

Is it a window named Asset/Editor? Do i have to create it myself?

Thanks

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 code-blep · May 15, 2013 at 09:14 PM 0
Share

If my answer below helped please mark this question as Answered Pauls :) Thanks.

3 Replies

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

Answer by code-blep · Nov 27, 2012 at 09:10 PM

Hi Pauls,

Inside Unity, look for the Project window. In that window see if there is a folder called 'Assets' if so go into the folder and see if there is a folder called 'Editor'. If the folders are not there, create them like any other folder.

When the folder structure is correct, drag and drop the Array Utility into the Editor folder.

Hope this helps.

Paul

Comment
Add comment · Show 5 · 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 Pauls · Nov 27, 2012 at 10:05 PM 0
Share

@UFOHunter Thanks a lot UFO Hunter, so i will have to create them. And what is Array utility? a file to drag and drop? Does it come with an asset i should import?

Thanks!

avatar image code-blep · Nov 27, 2012 at 10:59 PM 0
Share

I think we need to start at the beginning again ;)

I take it from the question you are looking to use arrays yes? If so we need to get back to what you actual need is. What will you be using your array for?

avatar image Pauls · Nov 28, 2012 at 12:03 AM 0
Share

I will need to fill in 2 arrays, one with gameObjects, and the second with the distance between each gameObject and a ball. So that i can sort the 1st array of gameObjects depending on the second array, (from max to $$anonymous$$) : so basically, if 3 game objects are near the ball, i put them in an array, i put their distance with the ball in another array, and i sort the distanceArray from max to $$anonymous$$, and i would need to know their index to sort the gameObjects array the same way. Then, when i push the "E" button, i can select a gameobject in the array, if i push again the E button, it goes to another gameobject etc. so that i can control any of the three gameObjects, just by switching them with the "E" button. Actually i am a bit confused, because indexOf is not what i would need, would you know how i could achieve this will all my informations? ;-) Thanks!

avatar image code-blep · Nov 28, 2012 at 08:08 PM 0
Share

O$$anonymous$$, it's a lot of stuff to cover here. Are you coding in C# or UnityScript? If it's UnityScript I'll give you some code to get you going, also I start the answer off by posting some links to essential reading to get you going, and will add code later if you are using UnityScript.

avatar image code-blep · Nov 28, 2012 at 08:23 PM 0
Share

Also I would change the title of your Question to something like Create Array of Transforms and Detect Distance, and then tag the question. If you do this then you will generate more $$anonymous$$arma points for yourself, and help other to find solutions ;)

avatar image
2

Answer by code-blep · Nov 28, 2012 at 08:11 PM

OK, to start here are some essential links for arrays:

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

http://docs.unity3d.com/Documentation/ScriptReference/Array.html

http://msdn.microsoft.com/en-us/library/d9hw1as6%28v=vs.90%29.aspx

I strongly recommend that you use ArrayLists, and virtually everyone will agree with this ;)

I'll add some examples now as other may find this useful anyway:

First you need to create an ArrayList to store your GameObjects. You actually need to store them as Transforms.

  • Create an empty GameObject and call it 'Start'

  • Create a new JavaScript and call it 'ObjectsArray', attach it to the 'Start' GameObject in your scene

  • Add the following code to the 'ObjectsArray' script:

    //Need this for the ArrayList function enter code here import System.Collections.Generic;

    //Create Your Array var allObjects = new List.();

You now have an array in a script called 'ObjectsArray' which you can add Transforms to.

  • Create a new script and call it 'AddMeToArray'

  • Add the following code to your script:

    //Create a Var so you can refer to the script var objectsArrayScript : ObjectsArray;

    function Start() { //Find the script
    objectsArrayScript = GameObject.Find("Start").GetComponent(ObjectsArray);

       //Adds the transform of the object this script is attached to our array
         objectsArrayScript.allObjects.Add(this.transform);
     }
    
    
    
    
  • You now need to attach the 'AddMeToArray' script to the parent of any GameObject you would like added to the array.

So all being well, then you start the game, each object will be added to the array.

Let me know how you get on with this, and when working we can take it further...

Here is a link to an example project I have put together for you: [1]: /storage/temp/5347-arrays+tutorial.zip


arrays tutorial.zip (105.3 kB)
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 code-blep · Nov 28, 2012 at 08:51 PM 1
Share

I have updated the code and this forum was doing funky stuff to it's formatting. It should be fine now but keep refreshing just in case ;)

avatar image Pauls · Nov 28, 2012 at 09:56 PM 0
Share

Thanks a lot, it is really nice from you, i'm more familiar with it now. I have also found some interesting stuffs, the main one is i think i should not iterate through all the gameobjects like how i planned to do, because i'm afraid of the performance (+ it is on mobile ;-) ) So i think i will use a physics function like overlap and check the layer attached to each gameobject that is close enough to the ball. Thanks anyway UFO Hunter, your messages were really helpful!

avatar image code-blep · Nov 28, 2012 at 09:57 PM 0
Share

No problem. Don't forget to vote one of these answers as accepted! Good luck!

avatar image
0

Answer by Bunny83 · Nov 28, 2012 at 10:35 PM

You got that page completely wrong. The notice at the top tells you that the ArrayUtility class (which is a built in class) belongs to the UnityEditor. It can't be used at runtime / in your game. It can only be used in editor scripts. Editor scripts are scripts that adds more functionality to the Unity editor. Editor scripts have to be placed in a folder called "Editor" inside your Assets folder. The UnityEditor namespace can / should only be used inside editor scripts. When you use this namespace in your normal game scripts you can't build your game since everything in this namespace belongs to the Unity editor which is not available when you ship your game.

Like UFO Hunter said, you should use a List instead. As a side note, the example in UFO Hunter's answer are written in UnityScript (Unity's javascript)

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 code-blep · Nov 28, 2012 at 10:48 PM 0
Share

@Bunny83: Thanks for clarifying! :)

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

12 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

Related Questions

A node in a childnode? 1 Answer

properly initializing my arrays (C#) 2 Answers

Remove object from List after gameObject was destroyed in between Scene loads 1 Answer

Tree Instance Array Replacement 2 Answers

Sorting Variables Help 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