Spawning Cars
I want to make a 3D game where my character is on a straight road with cars spwaning from the right and move left at different speeds. I want to know how do I spawn a certain number of gameObjects randomly at different speeds and z axis positions between two waypoints. Thanks
Answer by mahdiii · Mar 05, 2016 at 01:24 AM
You should make two scripts. One Generate_cars to generate cars and second Car script. In Car script you move your car with addforce or constant velocity or changing transform.position. Set speed and another variables for it. Assign this code to your car object and make prefab for it. In Generate_cars script you generate cars in special times (intervals) using IEnumerator and instantiate car prefabs into it.
class Generate_cars{ IEnumerator generate(){ GameObject carr; While(true){ yield return new WaitForSeconds(5f); carr=Instantiate(car_prefab) as GameObject; } } }
Your answer
Follow this Question
Related Questions
Shooting enemy to spawn them 0 Answers
AI Car Lane follow 0 Answers
Instantiate along the Z/X Axis only? 0 Answers
How to keep vehicles in correct lanes 0 Answers
Build and Run Unity 5 Error 1 Answer