The following Unity 2D C# script loads the ScoreBoard scene about every third or fourth time run, but it should load the ScoreBoard scene every time run. Most of the time, it fails to load the scene. The object is to destroy any game object that collides with an empty game object that has a box collider. If a house collides with the collider, the house is destroyed and the ScoreBoard scene loads. (Most of the time, it doesn't load). Any advice is appreciated.
using UnityEngine;
using System.Collections;
public class DestroyObjectsOnGround : MonoBehaviour {
void OnTriggerEnter2D(Collider2D collisionObject)
{
if (collisionObject.gameObject != null)
{
if (collisionObject.gameObject.tag == "house")
{
print ("house destroyed");
Destroy (collisionObject.gameObject);
Application.LoadLevel("ScoreBoard");
} else {
Destroy (collisionObject.gameObject);
}
}
}
}