Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

If condition not working on build?!

Discussion in 'Documentation' started by manueldanielmarcus, Jan 26, 2021.

  1. manueldanielmarcus

    manueldanielmarcus

    Joined:
    Jan 2, 2021
    Posts:
    1
    Hello there! Im new to unity and im having this problem where in the build the meteors wont destroy once hit by the rocket and with a few tests i noticed that the if condition is not working (the condition is check the name of the collision) also it works in editor which makes it more weird...
    Code (CSharp):
    1.     void OnTriggerEnter2D(Collider2D collision)
    2.     {
    3.         string high = PlayerPrefs.GetString("Highscore");
    4.         Highscore = float.Parse(high);
    5.         if (collision.gameObject.name == "meteor(Clone)")
    6.         {
    7.             difficulty = 1;
    8.             gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + 50, gameObject.transform.position.z); ;
    9.             Destroy(collision.gameObject);
    10.             inplayspace = false;
    11.             space.GetComponent<spacescript>().playing = false;
    12.             fade.GetComponent<Animator>().SetBool("fadein?", true);
    13.             timer2 = 0;
    14.             if (Highscore < Score)
    15.             {
    16.                 high = Score.ToString();
    17.                 Score = 0;
    18.                 PlayerPrefs.DeleteKey("Highscore");
    19.                 PlayerPrefs.SetString("Highscore", high);
    20.             }
    21.             else
    22.             {
    23.                 Score = 0;
    24.             }
    25.         }
    26.         else if (collision.gameObject.name == "PowerCube(Clone)")
    27.         {
    28.             GameObject col = collision.gameObject;
    29.             col.transform.position = new Vector3(col.transform.position.x, col.transform.position.y + 60, 0);
    30.             Instantiate(shield, new Vector3(gameObject.transform.position.x + 2, gameObject.transform.position.y, 3), Quaternion.identity);
    31.         }
    32.