Gun turrets and ammo
We've now created an ammo object (a projectile) and we've started to engineer a gun turret object, but it doesn't yet spawn ammo. Let's create this functionality now. We have a spawn point positioned in front of the turret parented to it as a child object. We'll attach a new script file called AmmoSpawner.cs to this object. This script is responsible for generating ammo at regular intervals. Refer to the following code:
//--------------------------------
using UnityEngine;
using System.Collections;
//--------------------------------
public class AmmoSpawner : MonoBehaviour
{
//--------------------------------
//Reference to ammo prefab
public GameObject AmmoPrefab = null;
//Reference to transform
private Transform ThisTransform = null;
//Vector for time range
public Vector2 TimeDelayRange = Vector2.zero;
//Lifetime for ammo spawned
public float AmmoLifeTime = 2f;
//Ammo Speed
public float AmmoSpeed = 4f;
//Ammo Damage...