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 ValidAttacks() { if (NormalAttack.getInstance().attackTargetObj) //有效攻击 { Debug.Log("ValidAttacks()"); NormalAttack.getInstance().attackTargetObj.GetComponent <InjureSystem>().beInjured(100); //攻击特效 var sfxAudio = GameObject.Find("SFX").GetComponent <AudioSource>(); sfxAudio.clip = GameObject.FindWithTag("Player").GetComponentInChildren <HeroSounds>().normalAttackSFX[Random.Range(0, GameObject.FindWithTag("Player").GetComponentInChildren <HeroSounds>().normalAttackSFX.Length)]; sfxAudio.Play(); } }
IEnumerator doSkill(int skillKind) { NormalAttack.getInstance().attackTargetObj = null; Run.getInstance().finishRun(); m_animator.SetFloat("HeroSkillKind", skillKind); m_animator.SetBool("isHeroSkill", true); switch (skillKind) { case 0: { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; Physics.Raycast(ray, out hitInfo, 1 << LayerMask.NameToLayer("Terrain") | 1 << LayerMask.NameToLayer("Enemy")); //SmoothLookAt.getInstance().Init_Rotate(hitInfo.point); gameObject.transform.LookAt(hitInfo.point); yield return(new WaitForSeconds(.1f)); var prefabQ = Instantiate(Resources.Load("Prefab/BlindMonkQ"), GameObject.Find("Q_pos").transform.position, new Quaternion()); var vec1 = new Vector3(hitInfo.point.x, GameObject.Find("Q_pos").transform.position.y, hitInfo.point.z); var vec2 = GameObject.Find("Q_pos").transform.position; var dir = vec1 - vec2; Ray rayToTarget = new Ray(vec2, dir); ((GameObject)prefabQ).GetComponent <BlindMonkQ>().targetPos = rayToTarget.GetPoint(1000); break; } case 1: { Vector3 tarPos = new Vector3(Q_target.transform.position.x, GameObject.Find("Q_pos").transform.position.y, Q_target.transform.position.z); //SmoothLookAt.getInstance().Init_Rotate(tarPos); gameObject.transform.LookAt(tarPos); Run.getInstance().RunToPos(tarPos, true); Q_target = null; break; } default: break; } }
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { NormalAttack.getInstance().finishAttack(); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { NormalAttack.getInstance().AttackRateUpdate = Time.time - 1.2f; //移动 => 缩短攻击间隔(走A) }