using UnityEngine;
using System.Collections;

public class PowerUp : MonoBehaviour {

	public GameObject powerup;
	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Awake () {
	
	}

	void OnTriggerEnter (Collider other)
	{
		this.GetComponent<AudioSource> ().Play ();
		generatePowerups();
		Destroy (other.gameObject);
		Destroy (this.gameObject);


	}

	private void generatePowerups()
	{
		Instantiate (powerup, GeneratePosition(), Quaternion.identity);
	}
	
	private Vector3 GeneratePosition()
	{
		int x,z;
		x = UnityEngine.Random.Range (-8,8);
		z = UnityEngine.Random.Range (-8,8);
		
		return new Vector3 (x, 0, z);
	}


}
