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 /
avatar image
0
Question by Layas · Mar 18, 2017 at 08:05 AM · c#unity5freeze

Unity freezes every time I run one specific scene

I have different scenes that work fine except when I reach one specific scene. The different thing about this scene is the scripts. A game manager script and a card script. (The game is a personnalized memory game based on the memory card game). Every time I reach that scene, Unity freezes and I can't play it nor load another scene (using a loadonclick script). I am new to Unity and this is the first real problem I found. Especially when this same scene used to work fine when I first finished it yesterday... Anyway, here is the script I am currently using

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

public class CardScript : MonoBehaviour {

 public static bool DO_NOT = false; 

 [SerializeField]
 private int _state;
 [SerializeField]
 private int _cardValue;
 private bool _initialized = false;

 private Sprite _cardBack;
 private Sprite _cardFace;
 private GameObject _manager;

 void Start() {
     _state = 1;
     _manager = GameObject.FindGameObjectWithTag("Manager");

 }

 public void setUpGraphics() {
     _cardBack = _manager.GetComponent<GameManager>().getCardBack();
     _cardFace = _manager.GetComponent<GameManager>().getCardFace(_cardValue);

     flipCard();
 }

 public void flipCard() {

     if (_state == 0)
         _state = 1;
     else if (_state == 1)
         _state = 0;

     if (_state == 0 && !DO_NOT)
         GetComponent<Image> ().sprite = _cardBack;
     else if (_state == 1 && !DO_NOT)
         GetComponent<Image> ().sprite = _cardFace;
 }

 public int cardValue {
     get { return _cardValue; }
     set { _cardValue = value; }
 }
 //50
 public int state {
     get { return _state; }
     set { _state = value; }
 }

 public bool initialized {
     get { return _initialized; }
     set { _initialized = value; }
 }

 public void falseCheck() {
     StartCoroutine(pause());
 }

 IEnumerator pause() {
     yield return new WaitForSeconds(1);
     if (_state == 0)
         GetComponent<Image>().sprite = _cardBack;
     else if (_state == 1)
         GetComponent<Image>().sprite = _cardFace;
     DO_NOT = false;
 }

}

The part that I changed a lot lately was the flipcard part because I had some trouble getting it to work, so I'm guessing the problem could be coming from there?

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 tanoshimi · Mar 18, 2017 at 08:07 AM 0
Share

Where do you call setupGraphics or falseCheck?

avatar image Layas tanoshimi · Mar 19, 2017 at 11:06 PM 0
Share

in my other script, inside the initializecards function

void initializeCards() { for (int id = 0; id <2; id++) { for(int i = 1; i < 7; i++) {

                 bool test = false;
                 int choice = 0;
             while (!test) {
                 choice = Random.Range(0,cards.Length);
                 test = !(cards [choice].GetComponent <CardScript>().initialized);
             }
             cards[choice].GetComponent<CardScript>().cardValue = i;
             cards[choice].GetComponent<CardScript>().initialized = true;
             }
         }
     foreach (GameObject c in cards)
         c.GetComponent<CardScript>().setUpGraphics();
     if (!_init) {
         _init = true;
     }
     }
avatar image ShadyProductions Layas · Mar 20, 2017 at 11:09 AM 1
Share

Does your test bool in your while loop ever get set to true? If not this means you're in an infinite loop which will crash your application.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Layas · Mar 20, 2017 at 04:41 PM

Solved: The problem was inside the 2nd for loop. i was set from 0 to 7 covering 12 cards whereas in my scene, I had changed it to 16 and forgot to modify the range of i in the script from 0 to 9.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Unity freeze at custom parameters for 'Unwrapping.GenerateSecondaryUVSet()' 1 Answer

Getting UNET non-player actions to behave the same? 0 Answers

Localization don't work with the russian text, only english 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