Spawn a gameobject in random position within an area?

hello all, the problem is I have create some prefab gameobject and place them on different position, and I use OnTriggerEnter destroy them and spawn them, however I keep destroy and spawn again again and again, the gameobject starting out of my area, so how can I spawn them in random position within an area, can somebody help me with this case, thank a lot!
Sorry for my poor english, hope you guys understand.

here is my script:

public GameObject cube;

    void SpawnCube(){

	Vector3 position = new Vector3(Random.Range(-10.0F, 10.0F), 1, Random.Range(-10.0F, 10.0F));
	Instantiate (cube, position, Quaternion.identity);
}

    void OnTriggerEnter(Collider collider){
	if (collider.gameObject.name == "player") {
		Destroy (this.gameObject);
		SpawnCube();
		
	}
}

All you have to do is swap the line Destroy (this.gameObject); and the line SpawnCube(). You can’t create another cube when you have destroyed this one and therefore destroyed this instance of the script before it creates the new cube!
As for the positioning, check the scaling of your prefab.

Destroy (this.gameObject);
SpawnCube();

You are calling this script over and over again while the player is in the trigger, destroy and then spawn.

I don’t fully know what you are looking for but try this.
Try using.

void OnTriggerExit(Collider collider){
    if (collider.gameObject.name == "player") {
        SpawnCube();
    }

   void OnTriggerEnter(Collider collider){
    if (collider.gameObject.name == "player") {
        Destroy (this.gameObject);
    }