using UnityEngine;
using System.Collections;

public class SpikyZone : MonoBehaviour {

	public GameObject sampleSpike;
	public float spikeSpacing;

	// Use this for initialization
	void Start () {
		Vector3 v = sampleSpike.transform.localScale;
		v.x /= transform.localScale.x;
		sampleSpike.transform.localScale = v;

		if (spikeSpacing < 0.01) spikeSpacing = 0.25f;
		float hsi = spikeSpacing;
		bool bDouble = true;
		while (hsi <= transform.localScale.x/2)
		{
			if (bDouble)
			{
				GameObject go = Instantiate<GameObject>(sampleSpike);
				go.transform.SetParent(this.transform,false);
				go.transform.position = sampleSpike.transform.position + new Vector3(hsi,0,spikeSpacing);
				
				go = Instantiate<GameObject>(sampleSpike);
				go.transform.SetParent(this.transform,false);
				go.transform.position = sampleSpike.transform.position + new Vector3(-hsi,0,spikeSpacing);

				go = Instantiate<GameObject>(sampleSpike);
				go.transform.SetParent(this.transform,false);
				go.transform.position = sampleSpike.transform.position + new Vector3(hsi,0,-spikeSpacing);
				
				go = Instantiate<GameObject>(sampleSpike);
				go.transform.SetParent(this.transform,false);
				go.transform.position = sampleSpike.transform.position + new Vector3(-hsi,0,-spikeSpacing);
			}
			else
			{
				GameObject go = Instantiate<GameObject>(sampleSpike);
				go.transform.SetParent(this.transform,false);
				go.transform.position = sampleSpike.transform.position + new Vector3(hsi,0,0);

				go = Instantiate<GameObject>(sampleSpike);
				go.transform.SetParent(this.transform,false);
				go.transform.position = sampleSpike.transform.position + new Vector3(-hsi,0,0);
			}
			hsi += spikeSpacing;
			bDouble = !bDouble;
		}
	}

}
