Having problems destroying an Object

OK, so Im trying to destroy an object and cant seem to work out why its not happening.
Basically Im at a terminal and want to switch a fence from activated to deactivated. Simply I want to destroy one object and spawn another in its place.

My script-

#pragma strict

var pickUp : AudioClip;
var lockedScreen : GameObject;
var unlockedScreen : GameObject;
var laserGateOpen : GameObject;
var laserGateClosed : GameObject;



function Start ()
{

}


function OnTriggerStay (other : Collider)
{
	
	// ... and the switch button is pressed...
    if (Input.GetKeyDown("i"))
       	{
            // ... deactivate the laser.				
			AudioSource.PlayClipAtPoint(pickUp, transform.position);
			Destroy(gameObject);
			Instantiate(unlockedScreen, lockedScreen.transform.position, Quaternion.identity);
			LaserFenceDeactivation();
		}					        
}


function LaserFenceDeactivation ()
{
	DestroyImmediate(laserGateClosed, true);
	Instantiate(laserGateOpen, laserGateClosed.transform.position, Quaternion.identity);
}

At first I simply used Destroy(laserGateClosed) but got this error message-

Destroying assets is not permitted to avoid data loss.
If you really want to remove an asset use DestroyImmediate (theObject, true);
UnityEngine.Object:Destroy(Object)
LaserFenceControl:LaserFenceDeactivation() (at Assets/Scripts/LaserFenceControl.js:34)
LaserFenceControl:OnTriggerStay(Collider) (at Assets/Scripts/LaserFenceControl.js:27)

But if I use DestroyImmediate I get this error -

Destroying GameObjects immediately is not permitted during physics trigger/contact or animation event callbacks. You must use Destroy instead.
UnityEngine.Object:DestroyImmediate(Object, Boolean)
LaserFenceControl:LaserFenceDeactivation() (at Assets/Scripts/LaserFenceControl.js:34)
LaserFenceControl:OnTriggerStay(Collider) (at Assets/Scripts/LaserFenceControl.js:27)

Maybe Im missing something but one seems to contradict the other ?

Any ideas plz guys ???

You aren’t working on instances of your Prefabs, but on the Prefab Originals themselves. @Supercouge has a good suggestion when he mentions to create the instances you are going to work with up front, and I concur. However, I wouldn’t be destroying and instantiating things over and over again; just set them to inactive.

GameObject fieldActiveGO;
GameObject fieldInactiveGO;

function Start()
{
    fieldActiveGO = Instantiate(fieldActivePrefab, transform.position, transform.rotation);
    fieldInactiveGO = Instantiate(field=InactivePrefab, transform.position, transform.rotation);
}

function ChangeFieldState(bool turnOn)
{
    fieldActiveGO.setActive(turnOn);
    fieldInactiveGO.setActive(!turnOn);
}

Creating and destroying objects is very slow, so avoid it when you can. In the case of flipping things back and forth between two states, obviously, you can just turn one on and the other off.

I guess that:

var laserGateOpen : GameObject;
var laserGateClosed : GameObject;

Are directly linked to your Prefab and not to an instantiated prefab (or clone Prefab).
It is usually better to work with instantiated prefab. It allow you, for example, to destroy the “Clone” by using Destroy(), anywhere you want in your script.

So in your Start() function, you should do something like this:

laserGateClosed = Instantiate(laserGateClosed, transform.position, Quaternion.identity);
laserGateOpen = Instantiate(laserGateOpen, transform.position, Quaternion.identity);

(you should do it for each of your prefab in fact, and each time you Instantiate a gameObject from a prefab). This way you will hold a clone object of your prefab, and, when you will call Destroy(), you will destroy the clone and not the prefab.