float high_distance = 4; //AI与Player的高度差小于这个值,停止高度追踪 ///<summary>AI按键输入合集</summary> void AiTakeKey() { transform_player = gObj_Player.GetComponent <Transform>(); if (all_attack_flag) { AI_all_attack(); } else { attackSystem.set_AttackObject_number(1); wuqi_number = 2; if (follow_flag) { if (Mathf.Abs(transform_player.position.x - transform.position.x) > far_distance || Mathf.Abs(transform_player.position.z - transform.position.z) > far_distance || Mathf.Abs(transform_player.position.y - transform.position.y) > high_distance || !is_onFloor) //水平方向追踪 { if (Mathf.Abs(transform_player.position.x - transform.position.x) > 2f || Mathf.Abs(transform_player.position.z - transform.position.z) > 2f) { w_downing = true; v = 1; } else { w_downing = false; v = 0; } mouse0_downing = false; } else { w_downing = false; v = 0; mouse0_downing = true; } if (transform_player.position.y - transform.position.y > high_distance) { high_follow_flag = true; } high_follow(); //高度追踪 } else { if (transform_player.position.y - transform.position.y > high_distance) { high_follow_flag = true; } high_follow(); //高度追踪 mouse0_downing = true; } } }
///<summary>记录选择的武器号码,设置选择某一武器时应有的UI</summary> void setWuqi_number() { if (!additional_ani_doing && !action_ani_doing) { if (Input.GetKeyDown(KeyCode.Alpha1)) { wuqi_number = 1; } if (Input.GetKeyDown(KeyCode.Alpha2)) { wuqi_number = 2; } if (Input.GetKeyDown(KeyCode.Alpha3)) { wuqi_number = 3; } if (Input.GetAxis("Mouse ScrollWheel") < 0) { if (wuqi_number < 3) { wuqi_number++; } } if (Input.GetAxis("Mouse ScrollWheel") > 0) { if (wuqi_number > 0) { wuqi_number--; } } if (wuqi_number == 1) { action_ani_arraynumber = 0; wuqilan.setOnesUp(wuqi_number - 1); attackSystem.set_AttackObject_number(0); } else if (wuqi_number == 2) { wuqilan.setOnesUp(wuqi_number - 1); attackSystem.set_AttackObject_number(1); } else if (wuqi_number == 3) { action_ani_arraynumber = 1; wuqilan.setOnesUp(wuqi_number - 1); attackSystem.set_AttackObject_number(2); } } }
///<summary>互斥动作中攻击部分的处理</summary> void huchi_action_gongji() { if (Input.GetKeyDown(KeyCode.Mouse0)) //按下鼠标左键 { if (wuqi_number == 1) //一号武器 { if (action_ani_number < action_ani_name[action_ani_arraynumber].Length) { if (mouse0_keytime - action_ani_lasttime > action_ani_doingtime[action_ani_arraynumber][max(action_ani_number - 1, 0)] || action_ani_number == 0) { action_ani_lasttime = Time.fixedTime; if (action_ani_number - 1 >= 0) { ani.SetBool(action_ani_name[action_ani_arraynumber][action_ani_number - 1], false); } ani.SetBool(action_ani_name[action_ani_arraynumber][action_ani_number], true); action_ani_number++; action_ani_doing = true; trailingmesh_1.setVisual(); trailingmesh_2.setVisual(); } } } if (wuqi_number == 3) //三号武器 { if (action_ani_number < action_ani_name[action_ani_arraynumber].Length) { if (mouse0_keytime - action_ani_lasttime > action_ani_doingtime[action_ani_arraynumber][max(action_ani_number - 1, 0)] || action_ani_number == 0) { action_ani_lasttime = Time.fixedTime; if (action_ani_number - 1 >= 0) { ani.SetBool(action_ani_name[action_ani_arraynumber][action_ani_number - 1], false); } ani.SetBool(action_ani_name[action_ani_arraynumber][action_ani_number], true); action_ani_number++; action_ani_doing = true; // trailingmesh_1.setVisual(); // trailingmesh_2.setVisual(); } } } if (wuqi_number == 4) //四号武器 { if (action_ani_number < action_ani_name[action_ani_arraynumber].Length) { if (mouse0_keytime - action_ani_lasttime > action_ani_doingtime[action_ani_arraynumber][max(action_ani_number - 1, 0)] || action_ani_number == 0) { action_ani_lasttime = Time.fixedTime; if (action_ani_number - 1 >= 0) { ani.SetBool(action_ani_name[action_ani_arraynumber][action_ani_number - 1], false); attackSystem.set_AttackObject_number(4); } else { attackSystem.set_AttackObject_number(3); } ani.SetBool(action_ani_name[action_ani_arraynumber][action_ani_number], true); action_ani_number++; action_ani_doing = true; } } } } if (action_ani_doing) //当互斥动画进行时 { if (Time.fixedTime - action_ani_lasttime < action_ani_doingtime[action_ani_arraynumber][action_ani_number - 1]) { if (wuqi_number == 1) //一号武器的动作效果 { transform.Translate(Vector3.forward * speed * Time.deltaTime); } if (wuqi_number == 3) //三号武器的动作效果 { // transform.Translate(Vector3.forward*speed*2.5f*Time.deltaTime); if (!is_onFloor) { transform.Translate(Vector3.up * -g_inScene * Time.deltaTime); } } if (wuqi_number == 4) //四号武器的动作效果 { if (action_ani_number == 1) { transform.Translate(Vector3.forward * speed * 2f * Time.deltaTime); } transform.Translate(Vector3.forward * speed * 0.5f * Time.deltaTime); } } if (wuqi_number == 1) //一号武器的攻击效果 { if (Time.fixedTime - action_ani_lasttime >= action_ani_doingtime[action_ani_arraynumber][action_ani_number - 1] && Time.fixedTime - action_ani_lasttime <= action_ani_doingtime[action_ani_arraynumber][action_ani_number - 1] + 0.01f) { attackSystem.set_Attack_flag(true); //创建或现实攻击用物体 } } if (wuqi_number == 3) //三号武器的攻击效果 { if (Time.fixedTime - action_ani_lasttime >= action_ani_doingtime[action_ani_arraynumber][action_ani_number - 1] - 0.4f && Time.fixedTime - action_ani_lasttime <= action_ani_doingtime[action_ani_arraynumber][action_ani_number - 1] - 0.39f) { attackSystem.set_Attack_flag(true); //创建或现实攻击用物体 } } if (wuqi_number == 4) //四号武器的攻击效果 { if (Time.fixedTime - action_ani_lasttime >= action_ani_doingtime[action_ani_arraynumber][action_ani_number - 1] && Time.fixedTime - action_ani_lasttime <= action_ani_doingtime[action_ani_arraynumber][action_ani_number - 1] + 0.01f) { attackSystem.set_Attack_flag(true); //创建或现实攻击用物体 } } if (Time.fixedTime - action_ani_lasttime > action_ani_delaytime[action_ani_arraynumber][action_ani_number - 1]) //倒计时 { ani.SetBool(action_ani_name[action_ani_arraynumber][action_ani_number - 1], false); ani.SetBool("defult", true); action_ani_number = 0; action_ani_doing = false; trailingmesh_1.setUnVisual(); trailingmesh_2.setUnVisual(); } setWASDandSpaceDefult(); //将WASD和空格相关的动画设置为默认状态 } else { WASD_and_Space_Down(); //按下WASD和空格键时的反应 } }