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 PaoSanchezBB · Dec 03, 2018 at 07:50 PM · error messagenumberbegginerbasic programmingoverflow

hello! Im a begginer trying to solve this. OverflowException: Number overflow. CreateGame..ctor () (at Assets/scripts/CreateGame.cs:28)

Hello,

Im trying to make a candy crush type game, i have the code and i think is ok, but there is this error on my console " , and the only thing i can make in my game is switch the candys, but there is no match.

my code:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Tile {

 public GameObject tileObj;
 public string type;
 public Tile(GameObject obj, string t)
 {
  tileObj = obj;
   type = t;
 }

}

public class CreateGame : MonoBehaviour {

 GameObject tile1 = null;
 GameObject tile2 = null;

 public GameObject[] tile;
 List<GameObject> tileBank = new List<GameObject>();

 static int rows = 9;
 static int cols = 6;
 bool renewBoard = false;
 Tile[,] tiles = (new Tile[cols, rows]);

 void ShuffleList()
 {
     System.Random rand = new System.Random();
     int r = tileBank.Count;
     while (r > 1)
     {
         r--;
         int n = rand.Next(r + 1);
         GameObject val = tileBank[r];
         tileBank[n] = tileBank[r];
         tileBank[r] = val;
     }
 }


 // Use this for initialization
 void Start () {

     int numCopies = (rows * cols) / 3;
     for(int i = 0; i < numCopies; i++)
     {
         for(int j = 0; j < tile.Length; j++)
         {
             GameObject o = (GameObject)Instantiate(tile[j], new Vector3(-10, -10, 0), tile[j].transform.rotation);
             o.SetActive(false);
             tileBank.Add(o);
         }
     }

     ShuffleList();

     for (int r= 0; r < rows; r++)
     {
         for(int c= 0; c < cols; c++)
         {
             Vector3 tilePos = new Vector3(c, r, 0);  
             for(int n= 0; n < tileBank.Count; n++)
             {
                 GameObject o = tileBank[n];
                 if (!o.activeSelf)
                 {
                     o.transform.position = new Vector3(tilePos.x, tilePos.y, tilePos.z);
                     o.SetActive(true);
                     tiles[c, r] = new Tile(o, o.name);
                     n = tileBank.Count + 1;
                 }
             }
         }
     }
 }
 
 // Update is called once per frame
 void Update () {

     CheckGrid();
     RenewGrid();
     if (Input.GetMouseButtonDown(0))
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit2D hit = Physics2D.GetRayIntersection(ray, 1000);

         if (hit)
         {
             tile1 = hit.collider.gameObject;
         }
     }
     
     else if (Input.GetMouseButtonUp(0) && tile1)
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit2D hit = Physics2D.GetRayIntersection(ray, 1000);

         if (hit)
         {
             tile2 = hit.collider.gameObject;
         }
         if (tile1 && tile2)
         {
             int horzDist = (int)Mathf.Abs(tile1.transform.position.x - tile2.transform.position.x);
             int vertDist = (int)Mathf.Abs(tile1.transform.position.y - tile2.transform.position.y);
             if (horzDist == 1 ^ vertDist == 1)
             { 
             Tile temp = tiles[(int)tile1.transform.position.x, (int)tile1.transform.position.y];
             tiles[(int)tile1.transform.position.x, (int)tile1.transform.position.y] = tiles[(int)tile2.transform.position.x, (int)tile2.transform.position.y];
             tiles[(int)tile2.transform.position.x, (int)tile2.transform.position.y] = temp;

             Vector3 tempPos = tile1.transform.position;
             tile1.transform.position = tile2.transform.position;
             tile2.transform.position = tempPos;

             tile1 = null;
             tile2 = null;
             }

         }
     }
 }

 void CheckGrid()
 {
     int counter = 1;
     for (int r = 0; r < rows; r++)
     {
         counter = 1;
         for (int c=1; c < cols; c++)
         {
             if (tiles[c, r] != null && tiles[c - 1, r] != null)
       {
         if (tiles[c, r].type == tiles[c - 1, r].type)
         {
                     counter++;
         }
         else
                 {
                     counter = 1;
                 }
                 if (counter == 3)
                 {
                     if (tiles[c, r] != null) tiles[c, r].tileObj.SetActive(false);
                     if (tiles[c - 1, r] != null) tiles[c - 1, r].tileObj.SetActive(false);
                     if (tiles[c - 2, r] != null) tiles[c - 2, r].tileObj.SetActive(false);
                     tiles[c, r] = null;
                     tiles[c - 1, r] = null;
                     tiles[c - 2, r] = null;
                     renewBoard = true;

                 }
     }
         }
     }

 for (int c= 0; c < cols; c++)
     {
         counter = 1;

         for (int r = 1; r < rows; rows++)
 {
 if (tiles[c, r] != null && tiles[c, r-1] != null)
             {
                 if (tiles[c, r].type == tiles[c, r - 1].type)
                 {
                     counter++;
                 }
                 else
                     counter = 1;

                 if ( counter == 3)
                 {
                     if (tiles[c, r] != null)
                         tiles[c, r].tileObj.SetActive(false);
                     if (tiles[c, r - 1] != null)
                         tiles[c, r - 1].tileObj.SetActive(false);
                     if (tiles[c, r - 2] != null)
                         tiles[c, r - 2].tileObj.SetActive(false);
                     tiles[c, r] = null;
                     tiles[c, r - 1] = null;
                     tiles[c, r - 2] = null;
                     renewBoard = true;
                 }
             }
     }
     }
 if ( renewBoard)
     {
         RenewGrid();
         renewBoard = false;

     }
 }

 void RenewGrid()
 {
     bool anyMoved = false;
     ShuffleList();
     for(int r = 1; r < rows; r++)
     {
         for (int c = 0; c < cols; c++)
         {

if (r == rows-1 && tiles[c, r] == null) { Vector3 tilePos = new Vector3(c, r, 0); for (int n = 0; n < tileBank.Count; n++) { GameObject o = tileBank[n]; if (!o.activeSelf) { o.transform.position = new Vector3(tilePos.x, tilePos.y, tilePos.z); o.SetActive(true); tiles[c, r] = new Tile(o, o.name); n = tileBank.Count + 1; }

                 }
             }

if (tiles[c, r - 1] == null) { tiles[c, r - 1] = tiles[c, r]; tiles[c, r - 1].tileObj.transform.position = new Vector3(c, r - 1, 0); tiles[c, r] = null; anyMoved = true; } } }

     }

 }



//[ ] > < ^

alt text

pls help me. tnks

sc.png (154.2 kB)
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

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.

Follow this Question

Answers Answers and Comments

160 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 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

UI elements not accessible due to protection level 0 Answers

Bracket error 1 Answer

Why do i get an error ? please help i've stuck for 20 min 1 Answer

Simple error but I'm just a begginer and cant figure this out, due to outdated API. 1 Answer

Enemy spawner - Spawning limited amount of enemies 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