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 Ian_coding · Dec 18, 2020 at 08:36 AM · repeating

How do I repeatedly execute a line of code but its modified by a number?

I am currently on a tic tac toe project and I need to code the draw system. to do that, I need to effectively check whether any of the circles or crosses and place and if so, set the corresponding boolean to true, or at least that is the method I have come up with. Once all are true, A draw boolean in another script is set to true and if there are no wins the game will end. The circles and crosses are numbered to their corresponding position on the grid and will have to be reached from another script named Variables.

here is my messed up rubbish script

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Draw : MonoBehaviour { bool GridSpace_1; bool GridSpace_2; bool GridSpace_3; bool GridSpace_4; bool GridSpace_5; bool GridSpace_6; bool GridSpace_7; bool GridSpace_8; bool GridSpace_9; Variables Var; void Start() { Var = GetComponent<Variables>(); } void Update() { for (int i = 9; i > 0; --i) { if (Var.Circle_[i].transform.position.y != 10) { //WHY IS THERE AN ERROR } } } }

P.S. IT DOESNT WORK

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Ian_coding · Dec 18, 2020 at 08:37 AM

I realised this might be confusing but by checking if the circles are not at the 10th y position, im checking if they are used

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
avatar image
0

Answer by Llama_w_2Ls · Dec 20, 2020 at 08:20 PM

This section here:

 for (int i = 9; i > 0; --i) 
 {
     if (Var.Circle_[i].transform.position.y != 10)
     {
 
     }
 }

Assumes that you have 10 elements in the public array Circle_ in your Var script. Which you probably don't or shouldn't have, since there's only 9 squares in a standard game of tic-tac-toe.


Instead, it should be:

     for (int i < 9; i >= 0; --i) 
     {
         if (Var.Circle_[i].transform.position.y != 10)
         {
     
         }
     }

Note: Remember that array indexing starts at 0, so myArray[0] is the FIRST element in the array and myArray[9] is the TENTH element in the array.


This should solve your 'error'. I did successfully manage to create a tic-tac-toe game, with win-checking and two player etc. but not drawing, since I did it in the Visual Studio console, in a console project, and not in Unity. I can help you further if you wish. @Ian_coding

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

110 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Repeat Bonus Sprite - UnityScript 0 Answers

How can I repeat an action after set number of seconds, 4 Answers

How to script a repeating environment texture 3 Answers

Invoke Repeating Rate 1 Answer

How best should I "repeat" a 2D platform level with finite width to make it endless? 2 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