This scripts being used to spawn 5 objects how can i addaped this to on left click shoot one of the objects towards the mouse and stop at that position and shoot the next on the next click until all 5 have been shot then use the first one again.
public class WeaponSpawn_Script : MonoBehaviour
{
public GameObject WeaponPrefab;
GameObject WeaponClone;
bool isSpawned = false;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isSpawned == false)
{
isSpawned = true;
WeaponClone = Instantiate(WeaponPrefab, transform.position, Quaternion.identity);
}
else if (Input.GetKeyDown(KeyCode.Space) && isSpawned == true)
{
isSpawned = false;
Destroy(WeaponClone);
}
}
}