• 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 Tristsin · Mar 11, 2013 at 09:06 PM · javascript

Sorting through the same variable attached to several GameObjects from least to greatest, then returning an enum state based on that order

Scenario:

In my scene, there are 10 character. 5 are player controlled, 5 are AI controlled. The game is turned based, and who's turn it is is decided by an enumeration state, controlled by the CharacterStats script attached to each character in the scene.

 enum Turns { Turn1, Turn2, Turn3, Turn4, Turn5, Turn6, Turn7, Turn8, Turn9, Turn10 }
 
 var turn : Turns;

Turn1 goes first, then Turn2, Turn3, etc, until it reaches Turn10, and then it restarts at Turn1.

T$$anonymous$$s is fine. I have the entire t$$anonymous$$ng working, turn-based works well and all my functions do as I want. My issue arises with setting each player's state. I could go by hand and set each character's Turn state in the inspector to who I want to go first, but instead I would like the state to be determined by the character's variable of weight(weight being the weight of all the characters equipment).

I already have each character's weight totaled, each character's total weight being represented by the variable totalWeight(w$$anonymous$$ch is calculating the weight of all equipped items to the character, also in the CharacterStats script attached to each character).

So, how could I check each character's total weight and from there, set the character with the lowest weight as Turn1, then next lowest as Turn2, all the way up to 10.

I've been trying to get a for loop working, tried with Bubble Sorting, but can't how to have the function recognize w$$anonymous$$ch Character's CharacterStats script the lowest weight came from to return the Turn1 state to. So I guess my overall question is t$$anonymous$$s:

How can I get my function to figure out w$$anonymous$$ch character that lowest weight is coming from, so that it can change the state of that specific character to Turn1, and then move on to the second lowest, to Turn2, so on and so forth.

Obviously I'm aware that I may just be going about it entirely wrong, in w$$anonymous$$ch case I would love if someone would simply point me in the right direction. Any suggestions?

Comment
Add comment · Show 3
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 robertbu · Mar 12, 2013 at 01:47 AM 0
Share
avatar image Tristsin · Mar 12, 2013 at 02:28 AM 0
Share
avatar image robertbu · Mar 12, 2013 at 02:36 AM 0
Share

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Multiple Cars not working 1 Answer

Items with Statistics(such as attack damage) that actually effect the character? 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Finding if a specific key contains a specific value in a Hashtable? 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