gameobject doesn't spawn in the assigned random positions?

In my game I have a game object that is supposed of be transporting in random positions but it is instantiating in the empty game object that has the script this is my code
using UnityEngine;
using System.Collections;

public class thingSpawner : MonoBehaviour {

public GameObject thing;
public float MaxObjectCount = 0;

// Use this for initialization
void Start () {
	StartCoroutine (TheSpawn ());
	thing.SetActive (true);

// Update is called once per frame
void Update () {


IEnumerator TheSpawn()
	while (true) {

		yield return new WaitForSeconds(Random.Range(1,6));

		thing.transform.position = new Vector3(Random.Range(-7f,5f),Random.Range(-4f,4f),Random.Range(0.7f,7f));
		GameObject clone = (GameObject) Instantiate(thing, transform.position,Quaternion.identity);





It seems like you are moving your “thing” and then destroy it.
But the new thing you instantiate gets the position of the object the script is attached to and
not the position of your moved old thing. The position of “this” gameobject didn’t change.
So depending on your intention (if you want to move or delete/recreate the object) you could either just change the transform.position parameter of instantiate to thing.transform.position or just delete your Instantiate and Destroy lines.

Hi adhamyasser,

I have read through your question and I am not entirely sure on what you are asking?

I assume you want the object to continuously teleport to new random positions.

If so then I would recommend moving start coroutine (Thespawn()) to update instead of start as in the start function it is only called once.

Also I would recommend the same thing for where you change thing.setactive to move it into update.

If you would like to give a bit more information on what exactly you are after and maybe an example then I am happy to assist further.

I hope this helps.

Kind Regards,