﻿using UnityEngine;
using System.Collections;

public class charControl : MonoBehaviour {

	Animation	anim;

	void Start () {
		anim = GetComponentInChildren<Animation>();
	}
	
	void Update () {
		Vector3 pos = transform.position;
		pos += transform.forward *Input.GetAxis ("Vertical") *Time.deltaTime *8.0f;
		transform.position = pos;

		float rotate_speed = 0.0f;
		rotate_speed = 360.0f* 0.4f* Input.GetAxis("Horizontal");
		transform.Rotate(new Vector3(0.0f,  rotate_speed  *Time.deltaTime, 0.0f));

		if(Input.GetButtonDown("Fire1")){
			GetComponent<Rigidbody>().AddForce(Vector3.up *300.0f);
		}


		if(Mathf.Abs(Input.GetAxis("Vertical"))>0.1f
		   ||Mathf.Abs(Input.GetAxis("Horizontal"))>0.1f){
				anim.CrossFade("10_walk", 0.3f);
		}else{
			anim.CrossFade("00_idle", 1.0f);
		}

		do{

		}while(false);

		


	}
}
