public void CheckAttack() { Collider[] colliders = Physics.OverlapSphere(transform.position, 2.5f, LayerMask.GetMask("Boss")); Debug.Log("Len" + colliders.Length); if (colliders.Length > 0) { for (int i = 0; i < colliders.Length; i++) { GameObject bosstemp = colliders[i].gameObject; //ConstantData.GetInstance().currBoss = bosstemp; //触发主角攻击 // AttackManager.GetInstance().PlayerAttack(transform.gameObject, bosstemp); //触发 boss 自动攻击 bosstemp.GetComponent <BossBase>().SetBossAttackState(true); //AttackManager.GetInstance().BossAutoAttack(bosstemp, transform.gameObject,2.0f); } GameObject currboss = colliders[0].gameObject; ConstantData.GetInstance().currBoss = currboss; //触发主角攻击 AttackManager.GetInstance().PlayerAttack(transform.gameObject, currboss); //触发 boss 自动攻击 currboss.GetComponent <BossBase>().SetBossAttackState(true); //AttackManager.GetInstance().BossAutoAttack(bosstemp, transform.gameObject,2.0f); Debug.Log("Attack the boss"); } }
/// <summary> /// 复活玩家 /// </summary> public void ResetPlayer() { ConstantData.GetInstance().Player.gameObject.SetActive(true); //ConstantData.GetInstance().Player.transform.position = new Vector3(ConstantData.GetInstance().Player.transform.position.x,0.5f, ConstantData.GetInstance().Player.transform.position.z); ConstantData.GetInstance().Player.GetComponent <PlayerBase>().InitPlayer(); ConstantData.GetInstance().Player.GetComponent <PlayerAnimCon>().Stand(); }
void Update() { //boss 当前为攻击状态 if (boss_attackstate) { timer -= Time.deltaTime; //检测寻路 if (CheckNavDistance(3f)) { bossnav.GetComponent <NavMeshAgent>().enabled = false; if (timer <= 0) { timer = TIME; AttackManager.GetInstance().BossAttack(transform.gameObject, ConstantData.GetInstance().Player); } } else if (CheckNavDistance(6f)) { bossnav.GetComponent <NavMeshAgent>().enabled = true; bossnav.destination = ConstantData.GetInstance().Player.transform.position; transform.GetComponent <BossAnimCon>().Run(); } //检测跟随攻击距离 CheckAttackDistance(6f); } }
public void ShowBossInfo(GameObject player, GameObject boss) { GameObject bossinfo = ConstantData.GetInstance().BossInfo; bossinfo.GetComponentInChildren <UISlider>().value = boss.GetComponent <BossBase>().GetBossBlood() / 100f; bossinfo.GetComponentInChildren <UILabel>().text = boss.GetComponent <BossBase>().GetBossName(); }
/// <summary> /// boss 攻击 /// </summary> /// <param name="boss"></param> /// <param name="player"></param> public void BossAttack(GameObject boss, GameObject player) { //boss 攻击状态 且 player 存活 if (boss.GetComponent <BossBase>().GetBossAttackState() && player.GetComponent <PlayerBase>().GetPlayerState()) { //boss.GetComponent<BossBase>().SetBossAttackState(true); boss.transform.LookAt(player.transform); boss.GetComponent <BossAnimCon>().Attack(); float temp = player.GetComponent <PlayerBase>().GetPlayerBlood() - boss.GetComponent <BossBase>().GetBossAttack(); if (temp > 0) { player.GetComponent <PlayerBase>().SetPlayerBlood(player.GetComponent <PlayerBase>().GetPlayerBlood() - boss.GetComponent <BossBase>().GetBossAttack()); ConstantData.GetInstance().PlayerHUD.GetComponent <HUDText>().Add(-boss.GetComponent <BossBase>().GetBossAttack(), Color.red, 0.5f); Debug.Log(player.GetComponent <PlayerBase>().GetPlayerName() + " 血量" + player.GetComponent <PlayerBase>().GetPlayerBlood()); Debug.Log("血量减少" + boss.GetComponent <BossBase>().GetBossAttack()); } else { player.GetComponent <PlayerBase>().SetPlayerBlood(0); player.GetComponent <PlayerBase>().SetPlayerState(false); player.GetComponent <PlayerBase>().SetPlayerAttackState(false); player.GetComponent <PlayerBase>().SetPlayerAutoAttackState(false); boss.GetComponent <BossBase>().SetBossAttackState(false); StopAllCoroutines(); boss.GetComponent <BossAnimCon>().Stand(); player.GetComponent <PlayerAnimCon>().Dead(); PublicFuncs.GetInstance().WaitTimeDoFun(0.5f, () => { player.SetActive(false); }); } ConstantData.GetInstance().PlayerInfo.GetComponentInChildren <UISlider>().value = player.GetComponent <PlayerBase>().GetPlayerBlood() / 100f; } }
/// <summary> /// 检测是否在跟随范围内 /// </summary> /// <param name="dis"></param> /// <returns></returns> public bool CheckNavDistance(float dis) { Debug.Log("检测是否跟随攻击"); float distance = Vector3.Distance(ConstantData.GetInstance().Player.transform.position, ConstantData.GetInstance().currBoss.transform.position); return(Mathf.Abs(distance) < dis); }
private void InitFacs() { LambdaFuncInt[] lfi = ConstantData.GetInstance().GetOnClickEvents(); string[][] st = ConstantData.GetInstance().GetFacilitiesInfo(); Resources tempPrice; Resources tmpProduct; for (int i = 0; i < st.Length; i++) { //make price tempPrice = new Resources(StringIntToIntArr(st[i][2])); tmpProduct = new Resources(StringIntToIntArr(st[i][5])); facs.Add(new Facility(Int32.Parse(st[i][0]), st[i][1], st[i][1] + "\n" + this.rm.GetFormattedResourceString(tmpProduct, true), "Activate " + st[i][1] + "\n" + this.rm.GetFormattedResourceString(tempPrice), tempPrice, tmpProduct, new Resources(StringIntToIntArr(st[i][3])), new Army(StringIntToIntArr(st[i][4])), new Army(StringIntToIntArr(st[i][6])), lfi[i] )); } facs[0].Activate(); }
/// <summary> /// 奔跑动画 /// </summary> public void Run() { IsAttackWQState(0); //animation.Stop(); animation.clip = clips[0]; animation.Play(); animation.CrossFade("ZhanLi_TY", 2.5f); ConstantData.GetInstance().BossInfo.SetActive(false); ConstantData.GetInstance().BossHUD = null; }
public void CheckBossActive() { //Debug.Log("检测boss 显示状态"); int len = ConstantData.GetInstance().BossList.Count; for (int i = 0; i < len; i++) { CheckDistance(ConstantData.GetInstance().BossList[i]); } }
/// <summary> /// 加载并初始化player /// </summary> private void InitPlayer() { GameObject playerprefab = LoadBundle("Player"); ConstantData.GetInstance().Player = Instantiate(playerprefab); GameObject playerhud = LoadBundle("PlayerHUD"); ConstantData.GetInstance().PlayerHUD = Instantiate(playerhud); ConstantData.GetInstance().PlayerHUD.GetComponent <UIFollowTarget>().target = ConstantData.GetInstance().Player.transform.Find("player_ui_point").transform; }
/// <summary> /// 设置Bloom特效 /// </summary> public void ChangeBloomEffect() { if (ConstantData.GetInstance().BlommEffectToggle.GetComponent <UIToggle>().value) { ConstantData.GetInstance().BloomEffect.SetActive(true); } else { ConstantData.GetInstance().BloomEffect.SetActive(false); } }
/// <summary> /// 设置键盘移动 /// </summary> public void ChangePlayerCon() { if (ConstantData.GetInstance().EasyTouchConToggle.GetComponent <UIToggle>().value) { ConstantData.GetInstance().Player.GetComponent <PlayerMove>().enabled = true; } else { ConstantData.GetInstance().Player.GetComponent <PlayerMove>().enabled = false; } }
public void CheckDistanceToStopAttack(float dis) { if (ConstantData.GetInstance().currBoss != null) { float distance = Vector3.Distance(ConstantData.GetInstance().Player.transform.position, ConstantData.GetInstance().currBoss.transform.position); if (Mathf.Abs(distance) > dis) { AttackManager.GetInstance().StopAttakc(); } } }
/// <summary> /// 主角npc自动攻击协程 /// </summary> /// <returns></returns> private IEnumerator PlayerAutoAttack() { while (ConstantData.GetInstance().Player.GetComponent <PlayerBase>().GetPlayerAutoAttackState()) { Debug.Log("Player 开始自动攻击"); ConstantData.GetInstance().Player.GetComponent <PlayerAnimCon>().Attack(); ConstantData.GetInstance().Player.GetComponent <PlayerAnimCon>().CheckAttack(); yield return(new WaitForSeconds(2.0f)); Debug.Log("Player 自动攻击"); } }
public void OnAttackBClick() { if (!ConstantData.GetInstance().Player.GetComponent <PlayerBase>().GetPlayerAttackState() && temptimeB < 0) { ConstantData.GetInstance().Player.GetComponent <PlayerAnimCon>().AttackB(); ConstantData.GetInstance().Player.GetComponent <PlayerAnimCon>().CheckAttack(); temptimeB = CDTime; } else { Debug.Log("技能冷却中"); } }
/// <summary> /// 检测boss是否在跟随攻击距离内 /// </summary> /// <param name="dis"></param> public void CheckAttackDistance(float dis) { Debug.Log(name + " 检测距离,停止攻击"); float distance = Vector3.Distance(ConstantData.GetInstance().Player.transform.position, ConstantData.GetInstance().currBoss.transform.position); //超出范围 停止攻击 if (Mathf.Abs(distance) > dis) { boss_attackstate = false; transform.GetComponent <BossAnimCon>().Stand(); bossnav.enabled = false; } }
public void PlayerAutoAttack(GameObject bossgamobj) { ConstantData.GetInstance().Player.GetComponent <NavMeshAgent>().enabled = true; ConstantData.GetInstance().Player.GetComponent <NavMeshAgent>().destination = bossgamobj.transform.position; ConstantData.GetInstance().Player.transform.LookAt(bossgamobj.transform); bossgamobj.transform.LookAt(ConstantData.GetInstance().Player.transform); ConstantData.GetInstance().Player.GetComponent <PlayerBase>().SetPlayerAttackState(true); //设置bossUI信息 ConstantData.GetInstance().BossInfo.SetActive(true); ConstantData.GetInstance().BossInfo.GetComponentInChildren <UISlider>().value = bossgamobj.GetComponent <BossBase>().GetBossBlood() / 100f; ConstantData.GetInstance().BossInfo.GetComponentInChildren <UILabel>().text = bossgamobj.GetComponent <BossBase>().GetBossName(); ConstantData.GetInstance().currBoss = bossgamobj; }
public void CheckDisAndAttack(float dis) { if (ConstantData.GetInstance().Player.GetComponent <PlayerBase>().GetPlayerAttackState()) { float distance = Vector3.Distance(ConstantData.GetInstance().Player.transform.position, ConstantData.GetInstance().currBoss.transform.position); ConstantData.GetInstance().Player.GetComponent <PlayerAnimCon>().Run(); if (Mathf.Abs(distance) < dis) { ConstantData.GetInstance().Player.GetComponent <PlayerBase>().SetPlayerAttackState(false); ConstantData.GetInstance().Player.GetComponent <PlayerBase>().SetPlayerAutoAttackState(true); player_auto_attack_state = true; ConstantData.GetInstance().Player.GetComponent <NavMeshAgent>().enabled = false; } } }
// Update is called once per frame void Update() { //主角死亡状态直接返回 if (!transform.gameObject.GetComponent <PlayerBase>().GetPlayerState()) { return; } //移动方向 Vector3 mDir = Vector3.zero; float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); if (h != 0 || v != 0) { if (Input.GetKey(KeyCode.W)) { mDir = new Vector3(FollowedCamera.transform.forward.x, 0, FollowedCamera.transform.forward.z); Quaternion newRotation = Quaternion.LookRotation(mDir); transform.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, 100); } else if (Input.GetKey(KeyCode.S)) { mDir = new Vector3(-FollowedCamera.transform.forward.x, 0, -FollowedCamera.transform.forward.z); Quaternion newRotation = Quaternion.LookRotation(mDir); transform.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, 100); } if (Input.GetKey(KeyCode.D)) { mDir = new Vector3(FollowedCamera.transform.right.x, 0, FollowedCamera.transform.right.z); Quaternion newRotation = Quaternion.LookRotation(mDir); transform.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, 100); } else if (Input.GetKey(KeyCode.A)) { mDir = new Vector3(-FollowedCamera.transform.right.x, 0, -FollowedCamera.transform.right.z); Quaternion newRotation = Quaternion.LookRotation(mDir); transform.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, 100); } transform.GetComponent <PlayerAnimCon>().Run(); ConstantData.GetInstance().Player.GetComponent <NavMeshAgent>().enabled = false; ConstantData.GetInstance().Player.GetComponent <PlayerBase>().SetPlayerAttackState(false); UIController.GetInstance().StopPlayerAutoAttack(); m_Controller.SimpleMove(transform.forward * 1.5f * Speed); } //检测boss 显示状态 CheckBossActive(); }
/// <summary> /// 添加boss /// </summary> public void AddBoss() { //prefab GameObject boss = LoadBundle("Boss"); //Vector3 newPos = RandomBossPosition(boss); int m = Random.Range(1, 6); int j = Random.Range(1, 6); Vector3 newPos = new Vector3(boss.transform.position.x + 10 * m, 0.008f, boss.transform.position.z + 10 * j); Quaternion rotation = boss.transform.rotation; GameObject newboss = Instantiate(boss, newPos, rotation); newboss.GetComponent <BossBase>().SetBossName("哥布林"); ConstantData.GetInstance().BossList.Add(newboss); UIController.GetInstance().AddBossItem(newboss); }
/// <summary> /// player 攻击 /// </summary> /// <param name="player"></param> /// <param name="boss"></param> public void PlayerAttack(GameObject player, GameObject bosstemp) { ShowBossInfo(player, bosstemp); //显示boss 信息 ConstantData.GetInstance().BossInfo.SetActive(true); //bosstemp.GetComponent<BossBase>().Attack(player.gameObject); float temp = bosstemp.gameObject.GetComponent <BossBase>().GetBossBlood() - player.GetComponent <PlayerBase>().GetPlayerAttack(); //boss 掉血 if (temp > 0) { bosstemp.GetComponent <BossBase>().SetBossBlood(bosstemp.GetComponent <BossBase>().GetBossBlood() - player.GetComponent <PlayerBase>().GetPlayerAttack()); PublicFuncs.GetInstance().WaitTimeDoFun(0.5f, () => { ShowBossInfo(player, bosstemp); }); GameObject bosshud = LoadBundle("BossHUD"); ConstantData.GetInstance().BossHUD = Instantiate(bosshud); ConstantData.GetInstance().BossHUD.GetComponent <UIFollowTarget>().target = bosstemp.transform.Find("boss_ui_point").transform; //ConstantData.GetInstance().BossHUD.GetComponent<UIFollowTarget>().target = bosstemp.transform; ConstantData.GetInstance().BossHUD.GetComponent <HUDText>().Add(-player.GetComponent <PlayerBase>().GetPlayerAttack(), Color.red, 0.5f); Debug.Log(bosstemp.GetComponent <BossBase>().GetBossName() + " 血量" + bosstemp.GetComponent <BossBase>().GetBossBlood()); Debug.Log("血量减少" + player.GetComponent <PlayerBase>().GetPlayerAttack()); } //boss 死亡 else if (bosstemp.GetComponent <BossBase>().GetBossState()) { bosstemp.GetComponent <BossBase>().SetBossBlood(0); player.GetComponent <PlayerBase>().SetPlayerAttackState(false); player.GetComponent <PlayerBase>().SetPlayerAutoAttackState(false); PublicFuncs.GetInstance().WaitTimeDoFun(0.8f, () => { ConstantData.GetInstance().BossList.Remove(bosstemp); bosstemp.GetComponent <BossAnimCon>().Dead(); StopAllCoroutines(); //隐藏死亡的boss PublicFuncs.GetInstance().WaitTimeDoFun(0.5f, () => { bosstemp.SetActive(false); ConstantData.GetInstance().BossInfo.SetActive(false); ConstantData.GetInstance().BossHUD = null; bosstemp.GetComponent <BossBase>().SetBossState(false); //update boss list bosstemp.GetComponent <BossBase>().bossinfo.SetActive(false); UIController.GetInstance().SortBossList(); }); }); } }
// Update is called once per frame void Update() { temptime -= Time.deltaTime; temptimeA -= Time.deltaTime; temptimeB -= Time.deltaTime; //ChangePlayerCon(); if (ConstantData.GetInstance().Player.GetComponent <PlayerBase>().GetPlayerAttackState()) { CheckDisAndAttack(3f); } if (player_auto_attack_state) { Debug.Log("开启协程 自动攻击"); StopAllCoroutines(); player_auto_attack_state = false; StartCoroutine(PlayerAutoAttack()); } //CheckDistanceToStopAttack(4.5f); }
void On_JoysticMove(MovingJoystick move) { float x = move.joystickAxis.x; float y = move.joystickAxis.y; float angle = 0; Vector3 mDir = Vector3.zero; Vector3 dir = Vector3.zero; //计算遥感偏移角度atan反正弦函数 得到弧度 在转换为 角度 if (y > 0) { angle = Mathf.Atan(x / y) * Mathf.Rad2Deg; } if (x < 0 && y < 0) { angle = Mathf.Atan(x / y) * Mathf.Rad2Deg - 180f; } if (x > 0 && y < 0) { angle = Mathf.Atan(x / y) * Mathf.Rad2Deg + 180f; } if (angle != 0) { ConstantData.GetInstance().Player.GetComponent <NavMeshAgent>().enabled = false; ConstantData.GetInstance().Player.GetComponent <PlayerBase>().SetPlayerAttackState(false); UIController.GetInstance().StopPlayerAutoAttack(); } //计算当前人物正方向 mDir = new Vector3(transform.position.x - FollowedCamera.transform.position.x, 0, transform.position.z - FollowedCamera.transform.position.z); //计算当前人物移动方向 即正方向转angle度 dir = Quaternion.AngleAxis(angle, transform.up) * mDir; //根据当前移动方向 计算人物角度值 Quaternion newRotation = Quaternion.LookRotation(dir); //人物转向 transform.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, 100); transform.GetComponent <PlayerAnimCon>().Run(); m_Controller.SimpleMove(dir * 1.0f); }
private void InitBossUI() { ConstantData.GetInstance().BossInfo.SetActive(false); }
private void InitPlayerUI() { //初始化 血量 Debug.Log("value " + ConstantData.GetInstance().PlayerInfo.GetComponentInChildren <UISlider>().value); ConstantData.GetInstance().PlayerInfo.GetComponentInChildren <UISlider>().value = GetPlayerBlood() / 100f; }
private GameObject LoadBundle(string name) { return(ConstantData.GetInstance().ab.LoadAsset <GameObject>(name) as GameObject); }
// Use this for initialization void Start() { target = ConstantData.GetInstance().Player.transform.Find("player_camera_target").transform; }