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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Editor and Build is different

Discussion in 'Scripting' started by Hello_Lp, Mar 4, 2014.

  1. Hello_Lp

    Hello_Lp

    Joined:
    Mar 23, 2013
    Posts:
    10
    $Screen Shot 2014-03-04 at 10.38.57 pm.png $Screen Shot 2014-03-04 at 10.39.24 pm.png
    Above are two files of the same game: one in editor and one is OSX Build.

    There problem seems from this

    Code (csharp):
    1.  
    2. public sealed class Cubes : MonoBehaviour
    3. {
    4.         private const string CUBE_NAME = "Cube";
    5.         public List<Cube> cubeList;
    6.  
    7.         public void Load (List<DataCube.Cube> cubeTypes)
    8.         {
    9. //10 cubes
    10.                 for (int i = 0; i < cubeList.Count; i++) {
    11.                         int random = UnityEngine.Random.Range (0, cubeTypes.Count);
    12.                         DataCube.Cube cube = cubeTypes [random];
    13.                         cubeList [i].Load (transform, cube.color);
    14.                 }
    15.         }
    16. }
    17.  
    18. public sealed class Cube : MonoBehaviour
    19. {
    20.         public void Load (Transform parent, Color color)
    21.         {
    22.                 transform.parent = parent;
    23.  
    24.                 bool isOverlay = false;
    25.                 do {
    26.                         float x = UnityEngine.Random.Range (0f, 1f);
    27.                         float y = UnityEngine.Random.Range (0f, 1f);
    28.  
    29.                         transform.position = Camera.main.ViewportToWorldPoint (new Vector3 (x, y, 10f));
    30.                         isOverlay = Physics.OverlapSphere (transform.position, 1f).Length > 0 ? true : false;
    31.                 } while(isOverlay);
    32.  
    33.                 renderer.enabled = true;
    34.                 renderer.material.color = color;
    35.                        
    36.                 gameObject.SetActive (true);
    37.         }
    38. }
    39.  
    Is there anything wrong with this code? If it works in the Editor, I can't see any reason why it should work in a build...
     
    Last edited: Mar 4, 2014
  2. Hello_Lp

    Hello_Lp

    Joined:
    Mar 23, 2013
    Posts:
    10
    Found the problem. It is how the XML file is loaded. Its different than the editor..