I have an in-game level editor, and upon loading a level file, it should
-Destroy any instance of “FakeBall”
-Load level (spawns GameObjects, which SHOULD but might not include a FakeBall)
-Check if there’s a FakeBall, if there isn’t then spawn one at 0,0,0
Here’s my code:
var fakeball : GameObject;
...
Destroy(GameObject.Find("FakeBall")); //Destroy FakeBall if there is one
if (System.IO.File.Exists(filePath + "/" + levelName + ".txt"))
{
//Parse level, and probably a FakeBall
}
if (GameObject.Find("FakeBall") == null)
{
fakeball = Instantiate(Resources.Load("FakeBall"), Vector3(0,0,0), Quaternion.identity);
fakeball.name = "FakeBall";
}
It seems to work fine in the editor, but not on my phone. Any ideas? I tried DestroyImmediate() instead of Destroy() too, and on the last “if” trying without “== null”
I found that the filepaths for the Unity editor is different than for Android, so I just had to use this in the Start() function:
if (Application.isEditor)
filePath = Application.dataPath;
else
filePath = Application.persistentDataPath;