Moving Projectile Instantiate Problem

I don’t mean to be brief but the following script creates the torpedo but doesn’t move to its target. Why is this? Can someone fix my code please?

using UnityEngine;
using System.Collections;

public class ForePhotonTorpedo : MonoBehaviour
{
	public GameObject photonTorpedo;
	float speed = 2f;

	void Update()
	{
		if (Input.GetKeyDown("z"))
		{
			var script = GameObject.Find("aaMain Camera").GetComponent<SelectTarget>();

			if (Mathf.Abs(Vector3.Angle(transform.forward, script.selectedTarget.transform.position - transform.position)) <= 125)
			{
				GameObject clone = Instantiate(photonTorpedo, transform.position, transform.rotation) as GameObject;
				clone.transform.position = Vector3.MoveTowards(transform.position, script.selectedTarget.transform.position, speed * Time.deltaTime);
			}
		}
	}
}

The move towards function is only being called when you press z, essentially 1 time for each torpedo. If you want it to move consistently, you will have to call that function each update.

I suggest that you attach a script to the photon torpedo prefab that calls that function in it’s update loop. Or, if you want this to be a torpedo manager, then store each instantiated torpedo in a List and move them each Update. Here is a script that should help. I blended both of the ideas I presented to you. Pick whichever way works best for you.

using System.Collections.Generic;
List<GameObject> activeTorpedos = new List<GameObject>();

void Update()
{
	if (Input.GetKeyDown("z"))
	{
		var script = GameObject.Find("aaMain Camera").GetComponent<SelectTarget>();
 
		if (Mathf.Abs(Vector3.Angle(transform.forward, script.selectedTarget.transform.position - transform.position)) <= 125)
		{
			GameObject clone = Instantiate(photonTorpedo, transform.position, transform.rotation) as GameObject;
			
			//You should probably just have this script on the prefab instead of adding it here
			ActiveTorpedo torpedo = clone.AddComponent<ActiveTorpedo>() as ActiveTorpedo:
			torpedo.target = script.selectedTarget.transform.position;
			
			//This is for if you want to keep track of the torpedos
			activeTorpedos.add(clone)
		}
	}
}


public class ActiveTorpedo : MonoBehaviour
{
	public Vector3 target;
	
	void Update()
	{
		if(target != null)
		{
			transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
		}
	}
	
	//possible explosion implementation
	void OnCollisionEnter(Collision collision) 
	{
		//BOOM!
		Destry(gameObject);
    }
}