// Update is called once per frame void Update() { CameraMoveControl(Input.mousePosition, camMoveSpeed); ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 2000f, layerScence)) { Debug.DrawLine(cam_pos.position, hit.point, Color.red); if (Input.GetMouseButtonDown(1)) { player_RoleMain.SetMoveTarget(hit.point); //角色移动调用 player_RoleMain.target = null; player_RoleMain.CanAtkNormal = false; } } if (Physics.Raycast(ray, out hit, 200f, layerPlayer)) { Debug.DrawLine(cam_pos.position, hit.point, Color.blue); if (Input.GetMouseButtonDown(0)) { Debug.Log("" + hit.transform.gameObject.name); player_RoleMain.SetTarget(hit.transform); } } Vector3 temp = hit.point - player.position; temp.y = 0f; player_RoleMain.skillLookDir = temp; }
void Update() { if (roleInfo.IsDeath) { agent.Stop(); aiOfHeroState = AIOfHeroState.death; } if (skillmanager.canAddSkill_Q) { skillmanager.AddSkill_Q(); skillmanager.CanShowAdd(); } if (skillmanager.canAddSkill_W) { skillmanager.AddSkill_W(); skillmanager.CanShowAdd(); } if (skillmanager.canAddSkill_E) { skillmanager.AddSkill_E(); skillmanager.CanShowAdd(); } if (roleInfo.Hp > 0) { Collider[] col = Physics.OverlapSphere(transform.position, 10.0f, roleInfo.EnemyLayer); //进入残血状态 if (roleInfo.Hp <= (roleInfo.HpMax / 2) && roleInfo.Hp >= 0) { aiOfHeroState = AIOfHeroState.halfBlood; } //进入遇敌状态 if (col.Length > 0 && aiOfHeroState != AIOfHeroState.halfBlood && roleInfo.Hp > 0) { aiOfHeroState = AIOfHeroState.meetEnemy; } //进入巡逻状态 if (aiOfHeroState != AIOfHeroState.halfBlood && col.Length == 0 && roleInfo.Hp > 0) { aiOfHeroState = AIOfHeroState.patrol; } //残血状态 if (aiOfHeroState == AIOfHeroState.halfBlood) { roleMain.SetMoveTarget(targetOfAI.target02.position); if (roleInfo.Hp == roleInfo.HpMax) { aiOfHeroState = AIOfHeroState.patrol; } } //巡逻状态 if (aiOfHeroState == AIOfHeroState.patrol && col.Length == 0) { Transform target = targetOfAI.target02; if (uimanager.mapSelect == MapSelect.oneVSone) { if (targetOfAI.target01 == null) { target = targetOfAI.target03; roleMain.SetMoveTarget(target.position); } else { target = targetOfAI.target01; roleMain.SetMoveTarget(target.position); } } else if (uimanager.mapSelect == MapSelect.threeVSthree) { if (!isGet) { roleMain.SetMoveTarget(targetOfAI.target_Roadpoint.position); } else { if (targetOfAI.target01 == null) { target = targetOfAI.target03; roleMain.SetMoveTarget(target.position); } else { target = targetOfAI.target01; roleMain.SetMoveTarget(target.position); } } } } //遇敌状态 if (aiOfHeroState == AIOfHeroState.meetEnemy && roleInfo.Hp > 0) { atkTimeCount += Time.deltaTime; Q_skillTimeCount += Time.deltaTime; W_skillTimeCount += Time.deltaTime; E_skillTimeCount += Time.deltaTime; //获取范围内敌人信息,跟随最近敌人 float minDistance = Vector3.Distance(transform.position, col [0].transform.position); int chioce = 0; for (int i = 0; i < col.Length; i++) { float currentDis = Vector3.Distance(transform.position, col [i].transform.position); if (currentDis < minDistance) { chioce = i; } } if (col [chioce].transform != null) { roleMain.SetMoveTarget(col [chioce].transform.position); } //在一定范围内攻击 if (Vector3.Distance(transform.position, col [chioce].transform.position) <= roleInfo.attack_Radius) { // if (atkTimeCount >= (1 / roleInfo.attack_Speed)) { // //英雄普通攻击 // roleMain.Akt_normal (); // atkTimeCount = 0; // } if (Q_skillTimeCount >= 3f) { //英雄技能Q roleMain.SetSkill_Q(); Q_skillTimeCount = 0; } if (W_skillTimeCount >= 5f) { //英雄技能W roleMain.SetSkill_W(); W_skillTimeCount = 0; } if (E_skillTimeCount >= 7f) { //英雄技能E roleMain.SetSkill_W(); E_skillTimeCount = 0; } } if (col.Length == 0) { aiOfHeroState = AIOfHeroState.patrol; } } } }