#pragma strict

private var agent : NavMeshAgent;	//NavMeshAgent^̕ϐagent
private var velocity : float;	//xpfloat^ϐ
private var direction : Vector3;	//݈ʒu
private var anim : Animator;	//Animator^anim

function Start() {
	agent = GetComponent(NavMeshAgent);	//NavMeshAgentR|[lgQƂagentɐݒ肵܂
	anim = GetComponent(Animator);	//AnimatorR|[lgQƂanimɐݒ肵܂
	direction = transform.position;	// directionɌݒn
}

function Update() {
	velocity = ((transform.position - direction).magnitude) / Time.deltaTime;	//xv
	direction = transform.position;	//݈ʒuXV

	if(Input.GetMouseButtonDown(0)) {
		var screenRay : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);	//J}EXŃNbNƂRay΂
		var hit : RaycastHit;
		if(Physics.Raycast(screenRay, hit))	//RayƂ𔻒
		{
			agent.SetDestination(hit.point);	//RayqbgʒuɈړ
		}
	}

	if(velocity > 0)	//x0ȏ (=ړȂ)
	{
		anim.SetBool("speed", true);	//Animator"speed"p[^trueɂ
	} else {
		anim.SetBool("speed", false);	//Animator"speed"p[^falseɂ
	}
}