// Update is called once per frame void Update() { record.traget = tragetposition; //方向分配--------------------------------------------------------------------------------- if (unit.commendMode == 3) { RaycastHit hit; if (Physics.Raycast(transform.position, tragetposition.transform.position - transform.position, out hit, 20, 2)) { if (uncollision && hit.transform.tag == "Player") { manager.detourRequest(hit.transform.gameObject, gameObject); } } //Debug.Log("Enter update"); if ((new Vector2(tragetposition.transform.position.x, tragetposition.transform.position.z) - new Vector2(transform.position.x, transform.position.z)).magnitude > 0.2) { if (record.obstacle != null) { action.move_AI_player(record.forward); // Debug.Log("In AI endPoint is" + record.endPoint); } else { //Debug.Log("Enter move"); action.move_AI_player(tragetposition.transform.position - transform.position); } } else { action.stay_AI_player(); } uncollision = true; //攻擊---------------------------------------------------------------------------------- attacktraget = manager.gettraget(unit.No); action.arrow_AI_player(attacktraget); if (!Physics.Raycast(transform.position, -transform.forward, out hit, 100, 2)) {//如果攻擊目標和物體之間沒有障礙物 action.attack_AI_player(); } else if (hit.transform.gameObject == attacktraget) {//如果障碍物是攻击目标 action.attack_AI_player(); //Debug.Log(" have obs in mood3 "+hit.transform.name); } } }
// Update is called once per frame void Update() { if (unit.commendMode == 2) { record.traget = traget; action.arrow_AI_player(traget); RaycastHit hit; if (Physics.Raycast(transform.position, -transform.forward, out hit, 100, 2))//使用射线观察前方有没障碍 { if (uncollision) { //Debug.Log("enter ray"); //Debug.Log("enter hit is" + hit.transform.name); if (hit.transform.gameObject != traget) { //Debug.Log("ENTER !="); manager.detourRequest(hit.transform.gameObject, gameObject); } else//如果前面的是目標則攻擊 { //Debug.Log("ENTER else1"); action.attack_AI_player(); } } else { // Debug.Log("non uncollision"); } } else//沒有障礙就攻擊 { //Debug.Log("ENTER else1"); action.attack_AI_player(); } // Debug.Log("record forward is" + record.forward+"endpoint is"+record.endPoint); if (record.obstacle != null) { action.move_AI_player(record.forward); // Debug.Log("In AI endPoint is" + record.endPoint); } else { action.move_AI_player(traget.transform.position - transform.position); } uncollision = true; //Debug.Log("in AI attack traget is"); } }
// Update is called once per frame void Update() { //移動----------------------------------------------------------- traget = manager.gettraget(unit.No); record.traget = traget; move = false; RaycastHit hit; if (tragettool != null) { if (Physics.Raycast(transform.position, traget.transform.position - transform.position, out hit, 20, 2) && hit.transform.gameObject != tragettool) { manager.detourRequest(hit.transform.gameObject, gameObject, tragettool.transform.position); } } else { if (Physics.Raycast(transform.position, traget.transform.position - transform.position, out hit, 20, 2) && hit.transform.gameObject != traget)//如果有障礙,繞過障礙 { Debug.Log(hit.transform.name); if (uncollision && hit.transform.tag == "Player") { manager.detourRequest(hit.transform.gameObject, gameObject); } } else { float distance = (traget.transform.position - transform.position).magnitude; Debug.Log("distance is" + distance); if (attribute.attackSkill && attribute.skillConsume - unit.nowMP >= -5)//如果是攻擊型技能且將可以施放 { if (distance > attribute.skillRanage) { move = true; } } if (distance > attribute.attackRange) { move = true; } } } //進行移動 if (tragettool == null) { if (record.obstacle != null) { action.move_AI_player(record.endPoint - transform.position); // Debug.Log("In AI endPoint is" + record.endPoint); } else if (move) { action.move_AI_player(traget.transform.position - transform.position); } else { action.stay_AI_player(); } } else { if (record.obstacle != null) { action.move_AI_player(record.endPoint - transform.position); // Debug.Log("In AI endPoint is" + record.endPoint); } else { action.move_AI_player(tragettool.transform.position - transform.position); } } uncollision = true; //轉向-------------------------------------------------------------------- action.arrow_AI_player(traget); //攻擊-------------------------------------------------------------------- if (Physics.Raycast(transform.position, traget.transform.position - transform.position, out hit, 20, 2) && hit.transform.gameObject == traget) { action.attack_AI_player(); } // }