Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Sheckerol · Aug 12, 2016 at 09:41 AM · array of gameobjectsbooleansmultiple-objectsturn based

How do get multiple variables from different objects to test if they are true?

I am trying to set up a turn based game where I move my team then the computer moves theirs, and I want to detect when all of them are done moving so that I can switch the turn over. I have this in all of the scripts I want to check.

     public class PlayerScript : MonoBehaviour
 
          public bool 
                  HasNoMovement;
          public float 
                  RemainingMovement;
          void Update()
         {
               if (RemainingMovement == 0)
                      HasNoMovement = true;
         }

From here on out is where everything kinda falls apart for me, on another script I have

 public class TurnManagerScript : Monobehaviour{
  
              private bool
                          PlayerTurn;
              private GameObject[]
                          Players;
              private int 
                          PlayerNumber;
             
               void Update()
               {
                       if (Players[PlayerNumber].GetComponent<PlayerScript>().HasNoMovement == true)
                                     PlayerNumber++;
                       if (PlayerNumber > Players.Length)
                                     EndingThePlayerTurn();
             }

}

which doesn't work, and will not fire the EndingThePlayerTurn method. So my question is how do I get this second code to work?

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 Denvery · Aug 12, 2016 at 12:48 PM 1
Share

Hello! Please tell me what exactly doesn't work in your second script? As I can see, there is no errors in this code. $$anonymous$$ay PlayerNumber is not correct? Lets check: please insert Debug.Log("Player number = " + PlayerNumber) before the line if (PlayerNumber > Players.Length) and see the console.

avatar image Aeleck · Aug 12, 2016 at 02:28 PM 1
Share

It's very possible that it's 0 based indexing (on accident?) so your PlayerNumber will only ever equal the Players.Length - 1. You could try using

 if(PlayerNumber == Players.Length)

But as @Denvery said, logging is the best place to start since you don't know what values you are getting.

avatar image Sheckerol · Aug 12, 2016 at 06:30 PM 0
Share

It is spitting out zero, It doesn't appear to be incrementing it, I will try to see if there are other references to it.

avatar image Sheckerol · Aug 12, 2016 at 06:32 PM 0
Share

The only other reference is in the EndingThePlayerTurn method, which resets it to zero.

avatar image Sheckerol · Aug 12, 2016 at 06:36 PM 0
Share

Nvm, it was the zero Indexing. I forgot to save before I started playing which led to the all zero's. thank you for helping me!

1 Reply

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

Answer by Sheckerol · Aug 12, 2016 at 06:48 PM

After putting in the script @Denvery told me I found that I had made the mistake @Aeleck pointed out. I forgot that Players.Length was one higher than the index. I thank these two for helping me figure it out. It now looks like this public class TurnManagerScript : MonoBehaviour

              private bool
                     PlayerTurn;
              Private GameObject[]
                     Players;
              private int
                     PlayerNumber;
 
             void Update()
             {
                     if (Players[PlayerNumber].GetComponent<PlayerScript>().HasNoMovement == true)
                               PlayerNumber++;
                     If (PlayerNumber == Players.Length)
                              EndingThePlayerTurn();
Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to run the same script multiple times in code but with different instances of it 0 Answers

Instantiate prefabs at different position 2 Answers

Unable to effect movement on active game object 0 Answers

Accessing the array of a null item / Moving items in array 0 Answers

Grid-based 2D game (turn based): How should I get started? 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