- Home /
GameObject spawning on Editor, but not on Android
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"
Should your GameObject appear above another graphic? I had the same problem with GameObjects which are above a floor tile. In the editor and on some devices are all fine and on my mobile I could'nt see them, but there are there. Because for some reason they were behind the floot tile ins$$anonymous$$d above.
I made a script for all floor tiles which set their z position fix, so the GameObject above is now visible.
Answer by Derf321 · Mar 29, 2015 at 08:10 AM
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;
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Android touch 3d Object event 1 Answer
Cannot touch cloned prefabs 0 Answers
AdMob firebase destroy banner issue 0 Answers
Problem With touch and double touch 0 Answers