What you need to do is put a little extra code in the script you have the function “Application.LoadLevel()” Firstly, you need a boolean at the beginning of the script (like @multinfs has). Then, you need this after the Application.LoadLevel() or just before that function:
var toDestroy : GameObject = GameObject.Find(/*name of object here*/);
if(destroyOnLoad){
Destroy(toDestroy.gameObject);
}
In the end, it should look somewhat like this:
var destroyOnLoad : boolean = false;
function WhateverThisFunctionActuallyIsInYourGame (){
var toDestroy : GameObject = GameObject.Find("prefabPortal");
if(destroyOnLoad){
Destroy(toDestroygameObject);
}
Application.LoadLevel(/*whatever level you have here in quotes*/);
}
Well, if I get it right you want a object to be toggleable to be destroyed or not when a level is loaded, please correct me if I’m wrong. Now this could be made in a few ways but I think this would be a easy way:
First you create a prefab if you havent already of the object/objects, and then u just add a script with this:
var destroyOnLoad : boolean = false;
function Start() {
if(destroyOnLoad)
Destroy(gameObject);
}
I think it could be function Awake() too but I’m not really sure whats the difference