I have a strange problem. When I run my game in the editor, it is running perfectly. But when I am making a build of it, there is a strange bug. When I click on a ball in my game, it shouldrespawn after a few seconds. And it is working perfectly in the editor. But when I make a build of my game, the ball is not respawns. So after i have noticed the bug, I went back to Unity, and it is worked fine. Then i have created another build (both pc and web player), but still have that issue. I have made 3 different build, but still have the problem.
Sure, however it is working 100% inside unity in play mode. The problem only appears, when I create a build.
//Spawning script
//Inspector variables
var blinkingSphereSpawnTime : int; //When to spawn the Blinking Sphere
var blinkingSphere : Transform; //Add the blinking sphere prefab
var blackBoxSpawnTime : int; //When to spawn the Black Box after the Blinking Sphere
var blackBox : Transform; //Add the Black Box prefab
var movingBoxSpawnTime : int; //When to spawn the Moving Box after the Black Box
var movingBox : Transform; //Add the Moving Box prefab
var spereRespawnTimeMax : int = 5; //The maximum ammount of time between the destruction and the spawning of a sphere
var spawned : int; //Is the sphere spawned?
//Private variables:
private var startPosition; //The starting position of the objects
function Start ()
{
startPosition = Vector3(Random.Range(-6, 6), Random.Range(-4, 4), 0); //Generates a random spawning position
yield WaitForSeconds(blinkingSphereSpawnTime); //Waits for an ammount of time
Instantiate(blinkingSphere, startPosition, transform.rotation); //Creates the Blinking Sphere
spawned = 1; //This is set to one, so the code in the function Update can start to run
yield WaitForSeconds(blackBoxSpawnTime); //Waits for an ammount of time
Instantiate(blackBox, startPosition, transform.rotation); //Creates the Black Box
yield WaitForSeconds(movingBoxSpawnTime); //Waits for an ammount of time
Instantiate(movingBox, startPosition, transform.rotation); //Creates the Moving Box
}
function Update ()
{
if (spawned == 1) //If the spere is spawned
{
if (GameObject.Find("prefabEnemySpereBlink(Clone)") == "null") //If there are no sphere spawned
{
spawn(); //Activate the spawn function
spawned = 0; //Disable the code in the function update
}
}
}
function spawn()
{
yield WaitForSeconds(Random.Range(0, spereRespawnTimeMax)); //Waits for a random ammount of time before spawning
Instantiate(blinkingSphere, startPosition, transform.rotation); //Creates a new Blinking Spere
spawned = 1; //Re-enable the code in the function update
}
I have no idea why it works in the editor
the problem is here:
replace
if (GameObject.Find("prefabEnemySpereBlink(Clone)") == "null")
with if (GameObject.Find("prefabEnemySpereBlink(Clone)") == null) (without " " around null)
or esier if (!GameObject.Find("prefabEnemySpereBlink(Clone)"))