// 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() { if (Input.GetKeyDown(firstButton)) { action.attack_AI_player(); } }
// Update is called once per frame void Update() { if (unit.commendMode == 1) { //移動------------------------------------------------------------------------------------------ //Debug.Log("distance:" + (transform.position - master.transform.position).magnitude); if ((transform.position - master.transform.position).magnitude > MAX_DISTANCE && unit.master != null) //弱國和主角距離超過最大距離 { AIAction.move_AI_player(master.transform.position - transform.position); //AI移動 } else//否則AI靜止 { AIAction.stay_AI_player(); } traget = manager.gettraget(unit.No); //獲取管理者指派的最近目標 //轉向------------------------------------------------------------------------------------------- if (traget != null) { AIAction.arrow_AI_player(traget);//如果有目標,則朝向目標 } else if (unit.master != null) { AIAction.arrow_AI_player(master);//如果沒有目標.則朝向主角 } //攻擊-------------------------------------------------------------------------------------------- if (unit.nextAttack <= 0) { AIAction.attack_AI_player(); } } }
// Update is called once per frame void Update() { //转向-------------------------------------------------- Debug.Log("arrow"); action.arrow_AI_player(traget); //移动攻击-------------------------------------------------- if ((traget.transform.position - mytrans.position).magnitude > AttackRange) { action.move_AI_player(traget.transform.position - mytrans.position); } else { action.stay_AI_player(); } action.attack_AI_player(); }
// 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(); } // }