一个简单的Unpdata移动,为什么每次移动完,角色都会自动回到起始点?,肯定解惑.
void Update()
{
//设置动画
playerAni.SetFloat("Speed",this.speed);
//判断移动距离,如果到目标停止,否则继续移动
if(InteractionDistance(transform.position,targetPoint,1))
{
targetPoint = Vector3.zero;
speed = 0;
}else{
speed = 1f;
float length = Vector3.Distance(transform.position,targetPoint);
transform.position = Vector3.Lerp(transform.position,targetPoint,Time.deltaTime/length);
transform.LookAt(targetPoint);
}
//发射射线查找鼠标点击位置,
if(Input.GetMouseButtonDown(0))
{
RaycastHit hit;
if(Physics.Raycast(GetMouseRay(),out hit))
{
if(hit.collider.CompareTag("Ground"))
{
//设置点击目标为移动目的地
targetPoint = hit.point;
}
}
}
}