public float getRockerAngle() { if (UtilsScripts.TwoPointDistance2D(new Vector2(0, 0), m_ball.transform.localPosition) <= m_triggerMoveLength) { return(0); } return(UtilsScripts.TwoPointAngle(new Vector2(0, 0), m_ball.transform.localPosition)); }
void attackEnemy(float attackRange, float hurt) { // 在攻击范围内寻找攻击的对象 { GameObject attackTarget = UtilsScripts.minDistance(gameObject, m_gameScript.getAllEnemyList()); if (attackTarget != null) { if (UtilsScripts.TwoPointDistance3D(gameObject.transform.position, attackTarget.transform.position) <= m_attackRange) { // 让英雄面向敌人 { float angle = UtilsScripts.TwoPointAngle(new Vector2(gameObject.transform.position.x, gameObject.transform.position.z), new Vector2(attackTarget.transform.position.x, attackTarget.transform.position.z)); gameObject.transform.localRotation = Quaternion.Euler(0, angle, 0); } if (attackTarget.tag.CompareTo("Tower") == 0) { if (attackTarget.GetComponent <TowerScript>().hurtAndIsDie(hurt)) { m_gameScript.getEnemyTowerList().Remove(attackTarget); ToastScript.createToast("摧毁地方防御塔"); } } else if (attackTarget.tag.CompareTo("Soldier") == 0) { //// 添加攻击特效 //{ // GameObject prefabs = Resources.Load("Prefabs/shouji") as GameObject; // GameObject obj = MonoBehaviour.Instantiate(prefabs); // obj.transform.position = attackTarget.transform.position + new Vector3(0, 0.2f, 0); //} if (attackTarget.GetComponent <SoldierScript>().hurtAndIsDie(hurt)) { m_gameScript.getEnemySoldierList().Remove(attackTarget); } } } } } }
// Update is called once per frame void Update() { if (!m_character.isGrounded) { m_character.Move(Vector3.down * 10.0f * Time.deltaTime); } // 更新血条位置 m_bloodProgressBar.transform.position = Camera.main.WorldToScreenPoint(gameObject.transform.position) + new Vector3(0, 90, 0); { if (m_animator.GetCurrentAnimatorStateInfo(0).IsName("attack")) { m_animator.speed = 1.5f; } else { m_animator.speed = 1.0f; } } bool canMove = true; List <GameObject> enemyList; if (m_isEnemy) { enemyList = m_gameScript.getAllMyList(); } else { enemyList = m_gameScript.getAllEnemyList(); } if (enemyList.Count == 0) { if (m_isEnemy) { gameObject.transform.localRotation = Quaternion.Euler(0, -90, 0); } else { gameObject.transform.localRotation = Quaternion.Euler(0, 90, 0); } m_character.Move(gameObject.transform.forward * (Time.deltaTime * m_speed / (1.0f / 60.0f))); return; } // 在攻击范围内寻找攻击的对象 { GameObject attackTarget = UtilsScripts.minDistance(gameObject, enemyList); if (attackTarget != null) { if (UtilsScripts.TwoPointDistance3D(gameObject.transform.position, attackTarget.transform.position) <= m_attackRange) { canMove = false; if (m_canAttack) { m_animator.SetTrigger("attack"); // 让英雄面向敌人 { float angle = UtilsScripts.TwoPointAngle(new Vector2(gameObject.transform.position.x, gameObject.transform.position.z), new Vector2(attackTarget.transform.position.x, attackTarget.transform.position.z)); gameObject.transform.localRotation = Quaternion.Euler(0, angle, 0); } if (attackTarget.tag.CompareTo("Tower") == 0) { if (attackTarget.GetComponent <TowerScript>().hurtAndIsDie(m_attack)) { if (m_isEnemy) { m_gameScript.getMyTowerList().Remove(attackTarget); ToastScript.createToast("我方防御塔被摧毁"); } else { m_gameScript.getEnemyTowerList().Remove(attackTarget); ToastScript.createToast("摧毁地方防御塔"); } } } else if (attackTarget.tag.CompareTo("Soldier") == 0) { if (attackTarget.GetComponent <SoldierScript>().hurtAndIsDie(m_attack)) { if (m_isEnemy) { m_gameScript.getMySoldierList().Remove(attackTarget); } else { m_gameScript.getEnemySoldierList().Remove(attackTarget); } } } else if (attackTarget.tag.CompareTo("Hero") == 0) { if (attackTarget.GetComponent <Hero01Script>().hurtAndIsDie(m_attack)) { m_gameScript.getMyHeroList().Remove(attackTarget); ToastScript.createToast("您已阵亡"); } } m_canAttack = false; } } // 如果有敌方小兵距离自己3倍攻击范围之内的,则主动向这个小兵方向移动 else if (UtilsScripts.TwoPointDistance3D(gameObject.transform.position, attackTarget.transform.position) <= (m_attackRange * 3)) { // 让小兵面向敌人移动 { float angle = UtilsScripts.TwoPointAngle(new Vector2(gameObject.transform.position.x, gameObject.transform.position.z), new Vector2(attackTarget.transform.position.x, attackTarget.transform.position.z)); gameObject.transform.localRotation = Quaternion.Euler(0, angle, 0); } } else { if (m_isEnemy) { gameObject.transform.localRotation = Quaternion.Euler(0, -110, 0); } else { gameObject.transform.localRotation = Quaternion.Euler(0, 70, 0); } } } } if (canMove) { m_character.Move(gameObject.transform.forward * (Time.deltaTime * m_speed / (1.0f / 60.0f))); } }