why wont the instance of the object move after its been instantiated.

Hello, I was just wondering if you could proof read this script and tell me why my instance of an object wont move after its been instantated. It is supposed to spawn a clone of a cube in a specified position every second and move in the forward direction. Afterwards it will delete after a specified time. It’s doing everything right except it’s not moving forward.I have all the values and an object set in the inspector. I have this script on an empty game object and I have a gameobject that it will make instances of. Thanks.  Script:

using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour {

public GameObject enemy;
public float SpawnSpeed = 1f;
public float destroyTime;
public float MoveSpeed;
Transform MyTransform;

void Start () {
	MyTransform = transform;
	InvokeRepeating ("Spawn", SpawnSpeed, SpawnSpeed);
}

void Update () {
	MyTransform.Translate  (Vector3.forward * MoveSpeed * Time.deltaTime);
}

void Spawn(){
	Vector3 spawnLocation = new Vector3 (Random.Range (-5, 5), 1f, 0f);
	GameObject clone = (GameObject)Instantiate (enemy, spawnLocation, Quaternion.identity);
	Destroy (clone,destroyTime);
}
}

I think you are moving the object which is spawning the enemy and not the enemy itself thats why the object the script attached to is moving by transform.translate. To actually move the enemy you have to write clone.transforn.translate below instantiate line and above the deatroy line. Hope it helps. Ask me if you have sone doubts

The code is improperly written. just take the part inside the update ,as @fafase said, and put it in the update of a seperate script. Also put the destroy function in the start of the new script. attach that script to enemy and make the whole thing as a prefab. Prefab it by dragging your enemy from hierarchy to the project section. then its a prefab. This script should only intantiate. here is what it should look like:

SpawnEnemyScript:

public GameObject enemy;

public float SpawnSpeed = 1f;

void Start () {

 InvokeRepeating ("Spawn", SpawnSpeed, SpawnSpeed);

}

void Spawn(){

 Vector3 spawnLocation = new Vector3 (Random.Range (-5, 5), 1f, 0f);
 GameObject clone = (GameObject)Instantiate (enemy, spawnLocation, Quaternion.identity);

}

EnemyScript:

public float MoveSpeed;

public float destroyTime;

void Start(){

 Destroy(this.gameobject);

}
void Update(){

 this.tranform.Translate (Vector3.forward * MoveSpeed * Time.deltaTime);

}//this.transform means the transform of who ever is attached to this script

So now just drag your enemy prefab to the EnemySpawnScript’s enemy slot.

Hope this helps…