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 zero3growlithe · Dec 24, 2011 at 12:40 PM · arraychecksortingplace

On which place is my value in array?

I'm making nice race placing system and what i want to do now is to check on what place (after using MyArray.sort() function) is my value from MyArray after sorting. How do i do that? Script:

 var EnemyAI_1 : GameObject;
 var EnemyAI_2 : GameObject;
 var EnemyAI_3 : GameObject;
 var EnemyAI_4 : GameObject;
 var EnemyAI_5 : GameObject;
 var EnemyAI_6 : GameObject;
 var EnemyAI_7 : GameObject;
 
 function Update () {
     Ship1 = EnemyAI_1.GetComponent(EnemyShipAI).CheckActualPlace;
     Ship2 = EnemyAI_2.GetComponent(EnemyShipAI).CheckActualPlace;
     Ship3 = EnemyAI_3.GetComponent(EnemyShipAI).CheckActualPlace;
     Ship4 = EnemyAI_4.GetComponent(EnemyShipAI).CheckActualPlace;
     Ship5 = EnemyAI_5.GetComponent(EnemyShipAI).CheckActualPlace;
     Ship6 = EnemyAI_6.GetComponent(EnemyShipAI).CheckActualPlace;
     Ship7 = EnemyAI_7.GetComponent(EnemyShipAI).CheckActualPlace;
     Ship8 = gameObject.GetComponent(ActualDistFromFinish).CheckActualPlace;

     var Place = new Array (Ship1,Ship2,Ship3,Ship4,Ship5,Ship6,Ship7,Ship8);
     Place.Sort();
     print(Place);
     
 }
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 Eric5h5 · Dec 24, 2011 at 01:14 PM 1
Share

It would be far easier and more flexible if you used a GameObject[] array or List rather than a bunch of individual variables, and it would be faster and better code if you use List.<GameObject> ins$$anonymous$$d of Array.

1 Reply

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

Answer by tomekkie2 · Dec 24, 2011 at 01:05 PM

You could create a function that returns an index of a GameObject element in array.

use a builtin GameObject[] array

function indexOf(arr : GameObject[], element:GameObject) {
    var l1 = arr.Length;
    var ind:int = 0;
    for (var i=0; i<l1; i++) {
        if(arr[i]==element) {
            ind = i;
            break;
        }
    }

and then:

........

Place.Sort(); var Places: GameObject[] = Place.ToBuiltin(GameObject); var indexInArray = indexOf(Places, Ship2) print(indexInArray);

Comment
Add comment · Show 2 · 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 zero3growlithe · Dec 24, 2011 at 03:21 PM 0
Share

Thanks for answer but the problem here is that my element in array is not an gameObject, it is a float.

avatar image tomekkie2 · Dec 24, 2011 at 03:30 PM 1
Share

if it is float, you just put float ins$$anonymous$$d of GameObject and float[] ins$$anonymous$$d of GameObject[]

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sort Array Of GameoObjects useing a variable 1 Answer

Change index values in list 0 Answers

How to sort an array ? 1 Answer

Looping through array to find a specific class? 0 Answers

i need a player list help please 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