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 ProjectCryken · Mar 26, 2013 at 07:27 PM · arraytagssorting

Creating A Basic Path For Enemies

I am unsure of how to achieve this in UnityScript:

1.Save all GameObjects with tag 'way' to an array

2.Sort the array alphabetically

3.Each 'way' object contains 4 GameObjects saved to variables named : 'path1' 'path2' 'path3' 'path4' in a script called 'WaypointScript'. Based on a number I supply it (1-4) it must go through the Array and save each path object from each way object in another array.

For example: Should the number supplied be 3, it would run through each way object and add the path3 variable to a new array. Resulting (If there were 4 way objects) with an array containing way1's path3, way2's path 3, way3's path3 and way4's path3.

Thanks a lot, I hope to learn from any answers I receive (Im not just being lazy)

Comment
Add comment · Show 5
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 whydoidoit · Mar 26, 2013 at 07:49 PM 0
Share

Can you post this script?

avatar image whydoidoit · Mar 26, 2013 at 07:50 PM 0
Share

Hang on, think I'm getting my head around it - why are you storing them as path1, path2 though - surely that should be an array as well?

avatar image ProjectCryken · Mar 26, 2013 at 07:55 PM 0
Share

There will only ever be 4, so I just created 4 different variables. Personal preference I guess.

avatar image whydoidoit · Mar 26, 2013 at 07:56 PM 0
Share

$$anonymous$$uch harder to write the code to access them though...

avatar image sdgd · Mar 26, 2013 at 07:59 PM 0
Share

well you can make an array:

 GameObject[] Path = new GameObject[4];

and here you have 4 new Game Object and you access them

Path[0] = ... ...;

and you can do a for loop if you'll have to

there you can't

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by whydoidoit · Mar 26, 2013 at 08:01 PM

I'd suggest you put your path1, path2 etc into an array. Then you can get your new array like this:

   import System.Linq;

   ...


   var taggedObjects = GameObject.FindGameObjectsWithTag("way");
   var pathNumber = 3;
   var path3 = taggedObjects
         .OrderBy(function(g) g.name)
         .Select(function(g) g.GetComponent(WayPointScript).path[pathNumber-1])
         .ToArray();


Using your existing method:

   var taggedObjects = GameObject.FindGameObjectsWithTag("way");
   var pathNumber = 3;
   var path3 = taggedObjects.OrderBy(function(g) g.name).Select(function(g) {
          var wayPointScript = g.GetComponent(WayPointScript);
          if(pathNumber == 1)
               return wayPointScript.path1;
          if(pathNumber == 2)
               return wayPointScript.path2;
          if(pathNumber == 3)
               return wayPointScript.path3;
          if(pathNumber == 4)
               return wayPointScript.path4;
   }).ToArray();
Comment
Add comment · Show 7 · 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 whydoidoit · Mar 26, 2013 at 08:02 PM 0
Share

Actually a switch rather than those ifs to be honest.

avatar image ProjectCryken · Mar 26, 2013 at 08:17 PM 0
Share

Im getting a missing $$anonymous$$ethod exception for .OrderBy

avatar image whydoidoit · Mar 26, 2013 at 08:19 PM 0
Share

At the top of your source:

  import System.Linq;
avatar image ProjectCryken · Mar 26, 2013 at 08:51 PM 0
Share

still happening :(

avatar image whydoidoit · Mar 26, 2013 at 09:01 PM 0
Share

I don't understand that works fine for me - see attached:

WExampleW

pathfinding.unitypackage.zip (7.9 kB)
Show more comments

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

Best way to list multiple tags... 2 Answers

How to create a table, array of array? 1 Answer

Need a Custom array Index to look up gameobject tags? 2 Answers

RandFuncs.Shuffle question 0 Answers

Code for gridColour[x,y] == gridColour[x+1,y] || colour at [x-1,y] || colour at [x,y+1] ||colour at [x, y-1] to detect if 4 of the same colours are connected? 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