• 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
Question by nickxp1 · Jan 11, 2016 at 03:43 PM · c#updateturn-based

Good Day! I have this code but I had an error

, for example (I set two players me, and 1 computer). I take the first turn, and the dice respawn with a value of 4 (just an example), the game piece then move from 1st to 4th tile when I touch the screen, when computer turns, it also move from 1st to 4th tile (because I set the result to 4 just an example). Now its my turn again, the dice never respawn and never wait to touch the screen if (Input.GetMouseButtonDown(0))and move again by 4...

void Update () { if (giveturn == true) { int h = 0; Giveturn(h); giveturn = false; }

 if (play == true) {

     if (pieces == true){
         SpawnPlayer();
         pieces = false;
     } 

     if (myturn == true){
         compturn = false;
         if(diceSpawn == true) {
             dice.transform.position = new Vector3(0,0,-1);
             diceclone = Instantiate(dice, dice.transform.position, Quaternion.identity) as GameObject;
             diceSpawn = false;
         }
         if (Input.GetMouseButtonDown(0))
         {
             Debug.Log("click");
             diceresult = 4;
             Destroy(diceclone);
             moving = true;
             Updateposition(diceresult);
         }
     }
     else
     {
         Debug.Log("comp");
         myturn = false;
         diceresult = 4;
         moving = true;
         Updateposition(diceresult);
     }
 }

}

void Giveturn(int k) { Debug.Log("" + k); currentPlayer = k; if (k == playerTurn) { Debug.Log("Yes"); compturn = false; myturn = true; diceSpawn = true; moving = false; } else
{ Debug.Log("No"); compturn = true; myturn = false; moving = false; } }

void Updateposition(int diceresult) { if (moving == true) { playerTileUp[currentPlayer] = playerTile[currentPlayer] + diceresult; Debug.Log("" + playerTileUp[currentPlayer]+ " " +currentPlayer); routine = true; StartCoroutine(MyMethod()); } moving = false; }

IEnumerator MyMethod() { if (routine == true) { if (myturn == true) { compturn = false; } else { myturn = false; }

     int f = playerTile[currentPlayer] + 1;
     Debug.Log(" " + currentPlayer ); 

     while (f <= playerTileUp[currentPlayer]) {
         Debug.Log("waiting");
         yield return new WaitForSeconds(1);
         Debug.Log(" " + Tile[f]);
         playerprefabC[currentPlayer].transform.position =  Tile[f].transform.position;
         Debug.Log(" " + currentPlayer);
         f++;
     }
     checking = true;
     TrapCheck();
 }
 routine = false;

}

void TrapCheck(){ if (checking == true) { if (playerTileUp[currentPlayer] == 8) { Debug.Log("Trap spawning"); Instantiate(situationCard[0], situationCard[0].transform.position, Quaternion.identity); population[currentPlayer] = population[currentPlayer] -1; }

     playerTile[currentPlayer] = playerTileUp[currentPlayer];
     Endturn();
     myturn = false;
     compturn = false;
     checking = false;
 }

}

void Endturn(){ currentPlayer++; Debug.Log(" " + currentPlayer); if (currentPlayer > compPlayer) { currentPlayer = 0; } Giveturn(currentPlayer); }

Comment

People who like this

0 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 gjf · Jan 09, 2016 at 04:21 PM 0
Share

please format ALL of your code...

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Need help with my code 0 Answers

MonoBehaviour Update called twice, fields being set to null 0 Answers

Update() and FixedUpdate() not running on C# scripts 0 Answers

Why i can't acces a global list in my class from OnDestroy() function 0 Answers

Problem with coroutine waiting 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