How to create meteors everywhere without making the game slow?

I am new to the community. I had by accidently made a thread on this on http://forum.unity3d.com/threads/170642-Meteors
So here’s what I had written… I have a controllable jet which constantly moves, and I want to make meteors everywhere. I have a prefab of the meteor. Of course I can’t make gazillion meteors everywhere in the scene, so I am planning to make new meteors appear in front of the jet and the meteors behind the jet to just get destroyed. How do I do this? The jet must be able to crash in on the meteors. I normally do code in C# but UnityScript (JavaScript) is fine…

There is a lot you can do. You are on the right track by have a limited number of meteors and moving and moving them in front of the jet. To determine if an object an be destroyed I would first check if it can be seen by the camera. There are a variety of ways: Take a look at the following. OnWillRenderObject, Renderer.isVisible, Renderer.OnBecameVisible, and OnBecameInvisible.

From this list of not visible meteors, I’d cull any objects that are unlikely to be seen and place them in front of the camera. Convert their positions to Viewport coordinates (Camera.WorldToViewportPoint()) Points that can be seen with have x and y values in the range of 0 to 1, and a positive Z value. Anything with a negative z value will be behind the camera. Anything with a value far outside the 0 to 1 range is highly unlikely to be seen by the ship even if it is turned somewhat.

You can use Viewport coordinates in placing the meteors to assure that they will be in or near the field of view.

As for making the meteors display efficiently, take a look at this page:

Draw Call Batching

There are limits (such as mesh complexity) to what can be batched, but when it usable, speed improvement can be substantial.

Thanks robertbu!!! I use a PC. The target platform is Web. The game is first person and the ship can move a full 360 in x axis. It can go up and down but turns 90 degrees when the KeyDown(KeyCode./*Up or Down*/) it moves up while KeyPress(KeyCode./*Up or Down*/) and turns front again on KeyUp(KeyCode./*Up or Down*/) The ship is moving with the transform.translate(0, 0, speed) speed is just a variable that increases when pressing the space-bar.

if(KeyPress(KeyCode.Space))
{
    speed++;
}
else if(speed > 10)
{
    speed--;
}

Will the destroying part work with a Vector3.Distance. You know, like

 float dist = Vector3.Distance(gameObject, /*spacecraft*/);    
    if(dist > /*some number*/)
    {
        Destroy(gameObject);
    }

Will it work if I attach this script to the prefab?