using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

	Rigidbody r_body;

	private float move_force = 10;
	private float max_speed = 100;

	public AudioClip SongStart;
	private AudioSource source;

	// Use this for initialization
	void Start () {
		r_body = GetComponent<Rigidbody>();
		source = GetComponent<AudioSource> ();
	}
	
	// Update is called once per frame
	void Update () {
		float h = Input.GetAxis("Horizontal");
		float v = Input.GetAxis ("Forward");

		r_body.AddForce(new Vector3(move_force * h, 0, move_force * v));

		if(r_body.velocity.x > max_speed)		{

			r_body.velocity = new Vector3(max_speed, 0, r_body.velocity.y);
		}
		else if(r_body.velocity.x < max_speed * -1)
		{
			r_body.velocity = new Vector3(max_speed * -1, 0, r_body.velocity.y);
		}
	}

	void OnCollisionEnter(Collision c)
	{
		Debug.Log ("Enter");
		source.PlayOneShot(SongStart, 1F);
	}



}
