IEnumerator Dash() { if (busy) { yield break; } busy = true; yield return(new WaitForSeconds(dashDelay)); for (int i = 0; i < dashCount; i++) { Vector3 direction; if (OnlyHorizontalDash == true) { direction = (new Vector3(player.position.x, transform.position.y, player.position.z) - transform.position).normalized; } else { direction = (player.position - transform.position).normalized; } float timer = 0f; while (timer < dashInteval) { body.velocity = new Vector2(0, 0); timer += Time.deltaTime; yield return(new WaitForEndOfFrame()); } timer = 0f; while (timer < dashDuration) { Physics2D.IgnoreCollision(box, playerBox, true); body.velocity = direction * dashSpeed; Collider2D[] cols = Physics2D.OverlapBoxAll(transform.position + direction * (box.size.x + hitboxWidth), new Vector2(hitboxWidth * 2, box.size.y), Vector2.SignedAngle(transform.position, player.position)); foreach (Collider2D col in cols) { if (col.CompareTag("player")) { playerControl.Die(); } } timer += Time.deltaTime; yield return(new WaitForEndOfFrame()); Physics2D.IgnoreCollision(box, playerBox, false); } timer = 0f; body.velocity = Vector2.zero; } busy = false; StartCoroutine(StartAttackTimer()); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag(GlobalTagDefine.TagName_player)) { PlayerControl1 _player = collision.GetComponent <PlayerControl1>(); if (_player != null) { _player.Die(); } else { Debug.Assert(false); } } else if (collision.CompareTag(GlobalTagDefine.TagName_thing)) { Thing _thing = collision.GetComponent <Thing>(); if (_thing != null) { if (_thing.type == Type.enemy) { Enemy _enemy = _thing.GetComponent <Enemy>(); if (_enemy != null) { _enemy.TakeDamage(DamageOfMelee); } else { Debug.Assert(false, string.Format("近战攻击到了一个没有enemy组件的敌人")); } } else { Debug.Assert(false, string.Format("非enemy该如何判断?")); } } else { Debug.Assert(false, string.Format("没有thing的物件")); } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag(GlobalTagDefine.TagName_player)) { PlayerControl1 _player = collision.gameObject.GetComponent <PlayerControl1>(); if (_player != null) { _player.Die(); } } else { if (collision.gameObject.CompareTag("thing")) { Thing colThing = collision.gameObject.GetComponent <Thing>(); if (colThing.type == Ben.Type.enemy) { colThing.GetComponent <Enemy>().TakeDamage(damage); } } } }
private void Update() { if (IsSkillCasting() == true) { if (m_fCurrentTime >= DashDuration) { SetSkillCasting(false); m_rigidBody.velocity = Vector2.zero; if (m_flipEnemy != null) { m_flipEnemy.UpdateValid(true); } } else { Vector3 vecSource = new Vector2(transform.position.x, transform.position.y - DashHitOffsetY); Physics2D.IgnoreCollision(m_ColliderBox, m_ColliderPlayerBox, true); m_rigidBody.velocity = m_vecDashDir * dashSpeed; float fAngle = Vector2.SignedAngle(transform.position, m_transPlayer.position); Collider2D[] cols = Physics2D.OverlapBoxAll(vecSource + m_vecDashDir * (m_ColliderBox.size.x + hitboxWidth), new Vector2(hitboxWidth * 2, m_ColliderBox.size.y), fAngle); foreach (Collider2D col in cols) { if (col.CompareTag("player")) { m_playerCtrl.Die(); } } Physics2D.IgnoreCollision(m_ColliderBox, m_ColliderPlayerBox, false); m_fCurrentTime += Time.deltaTime; } } }
IEnumerator DashAction(int nDashCount) { if (busy) { yield break; } busy = true; yield return(new WaitForSeconds(dashDelay)); //m_animator.SetInteger() for (int i = 0; i < nDashCount; i++) { Vector3 direction; if (OnlyHorizontalDash == true) { direction = (new Vector3(player.position.x, transform.position.y, player.position.z) - transform.position).normalized; } else { direction = (player.position - transform.position).normalized; } float timer = 0f; m_animator.SetInteger(m_nAnimatorChargingPara, 1); m_animator.SetInteger(m_nAnimatorAttackPara, 0); while (timer < dashInteval) { body.velocity = new Vector2(0, 0); timer += Time.deltaTime; yield return(new WaitForEndOfFrame()); } m_enemyFlip.ProcessFlip(true); yield return(new WaitForSeconds(rushDelay)); m_animator.SetInteger(m_nAnimatorChargingPara, 0); m_animator.SetInteger(m_nAnimatorAttackPara, 1); m_bDrawGizmos = true; timer = 0f; while (timer < dashDuration) { Vector3 vecSource = new Vector2(transform.position.x, transform.position.y - DashHitOffsetY); Physics2D.IgnoreCollision(box, playerBox, true); body.velocity = direction * dashSpeed; float fAngle = Vector2.SignedAngle(transform.position, player.position); Collider2D[] cols = Physics2D.OverlapBoxAll(vecSource + direction * (box.size.x + hitboxWidth), new Vector2(hitboxWidth * 2, box.size.y), fAngle); foreach (Collider2D col in cols) { if (col.CompareTag("player")) { playerControl.Die(); } } timer += Time.deltaTime; yield return(new WaitForEndOfFrame()); Physics2D.IgnoreCollision(box, playerBox, false); } m_animator.SetInteger(m_nAnimatorChargingPara, 0); m_animator.SetInteger(m_nAnimatorAttackPara, 0); m_bDrawGizmos = false; timer = 0f; body.velocity = Vector2.zero; } m_nBombCounts = 0; m_bThrowBomb = true; m_animator.SetInteger(m_nAnimatorChargingPara, 0); m_animator.SetInteger(m_nAnimatorAttackPara, 0); StartCoroutine(StartAttackTimer()); busy = false; }