-
if (anim.GetCurrentAnimatorStateInfo(0).IsName("Grounded"))
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isCollider = Physics.Raycast(ray, out hit);
Vector3 targetPosition = hit.point;
targetPosition.y = transform.position.y;
shootdir = targetPosition - transform.position;//鼠标点击 箭头生成的方向
transform.rotation = Quaternion.LookRotation(shootdir);//控制面向
anim.SetTrigger("Attack"); //控制角色动作
Invoke("Shoot",0.3f);// 实例箭
facade.PlayNormalSound(AudioManager.Sound_Alert);}
}
}这是攻击时的脚本...按老师所说的,但还是无法先转向(跑动过程中突然鼠标点击反方向,就好像跑动的动作还没停止就开始攻击动作了,但是面向没转过来)
下面是跑动的脚本
void FixedUpdate ()
{if (anim.GetCurrentAnimatorStateInfo(0).IsName("Grounded")==false)
{
return;
}
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if (Mathf.Abs(h) > 0 || Mathf.Abs(v) > 0)
{
transform.Translate(new Vector3(h, 0, v) * speed * Time.deltaTime, Space.World);
transform.rotation = Quaternion.LookRotation(new Vector3(h, 0, v));float res = Mathf.Max(Mathf.Abs(h), Mathf.Abs(v));
forward = res;
anim.SetFloat("Forward", res);
}}