public void MouseToMove() { if (Input.GetKey(KeyCode.Mouse1) && MoveOrAttackSwitch) //鼠标右键限定 { //Debug.Log("MouseToMove()"); var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; Physics.Raycast(ray, out hitInfo, 1 << LayerMask.NameToLayer("Terrain") | 1 << LayerMask.NameToLayer("Enemy")); //Debug.Log(hitInfo.point); if (hitInfo.collider.tag == "Terrain" && Mathf.Abs(Vector3.Distance(GameObject.FindWithTag("Player").transform.position, hitInfo.point)) > 1) //加限制 { //Debug.Log("Terrain"); Run.getInstance().RunToPos(hitInfo.point); //坐标 SmoothLookAt.getInstance().Init_Rotate(hitInfo.point); //朝向 NormalAttack.getInstance().attackTargetObj = null; } else if (hitInfo.collider.tag == "Enemy") { NormalAttack.getInstance().attackTargetObj = hitInfo.collider.GetComponentInParent <Enemy>().gameObject; } else { NormalAttack.getInstance().attackTargetObj = null; //清空普攻目标 } } }
public void MoveAndAttackTargetObj() { if (attackTargetObj) { foreach (var item in EnemyTriggerList) { if (item == attackTargetObj) { Run.getInstance().finishRun(); SmoothLookAt.getInstance().Init_Rotate(attackTargetObj.transform.position); //朝向 doAttack(); return; } } Run.getInstance().RunToPos(attackTargetObj.transform.position); //坐标 SmoothLookAt.getInstance().Init_Rotate(attackTargetObj.transform.position); //朝向 } }