IEnumerator DisableAirControl(Collider2D collision) { if (collision.CompareTag("player")) { yield return(new WaitForSeconds(delay)); ProCamera2DShake.Instance.Shake(0.2f, new Vector2(80f, 80f)); sr.enabled = false; box.enabled = false; pc.disableAirControl = true; pc.GetComponent <AirJump>().charge = pc.GetComponent <AirJump>().maxCharge; yield return(new WaitForSeconds(0.05f)); Rigidbody2D rb = collision.GetComponent <Rigidbody2D>(); rb.velocity = new Vector2(xSpeed, ySpeed); yield return(new WaitForSeconds(disableAirControlDur)); pc.disableAirControl = false; mrb.velocity = Vector2.zero; GetComponent <Thing>().dead = true; } else { Rigidbody2D rb = collision.GetComponent <Rigidbody2D>(); rb.velocity = new Vector2(xSpeed, ySpeed); ProCamera2DShake.Instance.Shake(0.2f, new Vector2(50f, 50f)); sr.enabled = false; box.enabled = false; GetComponent <Thing>().dead = true; } }
private void OnTriggerEnter2D(Collider2D collision) { if (selfEnemy.dead) { return; } if (collision.CompareTag(GlobalTagDefine.TagName_player) == true) { PlayerControl1 _ctrl = collision.GetComponent <PlayerControl1>(); if (_ctrl != null) { _ctrl.GetComponent <Thing>().Die(); StartCoroutine(_ctrl.DelayRestart()); } } else if (EnemyDamage == true && collision.gameObject.CompareTag("thing")) { Thing colThing = collision.gameObject.GetComponent <Thing>(); if (colThing != null) { if (colThing.type == Type.enemy) { colThing.GetComponent <Enemy>().TakeDamage(1); } } } }
void OnTriggerEnter2D(Collider2D other) { if (other.transform.CompareTag("player")) { PlayerControl1 player = other.GetComponent <PlayerControl1>(); if (player.GetComponent <Rigidbody2D>().velocity.magnitude < 2500f) { return; } if (isHeart) { player.hp += 1; player.maxhp += 1; } else { other.GetComponent <ThrowKunai>().kunai1.swapDamage += 1; other.GetComponent <ThrowKunai>().kunai2.swapDamage += 1; } PlayerControl1.Instance.GetComponent <AudioSource>().PlayOneShot(hitClip); Destroy(gameObject); } if (other.transform.CompareTag("floor")) { Destroy(gameObject); } }
public void Swap(Collider2D target, ref bool swapped) { if (target == null) { return; } player.rb.velocity = Vector2.zero; player.rb.gravityScale = 0f; //ScanEnemies(target); Collider2D _readySwapCol = target; Rigidbody2D thingBody = _readySwapCol.gameObject.GetComponent <Rigidbody2D>(); Thing _swapThing = _readySwapCol.gameObject.GetComponent <Thing>(); _swapThing.ThingSwap(); Thing _playerThing = player.gameObject.GetComponent <Thing>(); _playerThing.ThingSwap(); if (_swapThing.hasShield) { return; } Vector3 posPlayer = player.transform.position; Vector3 _posSwapThing = _readySwapCol.transform.position; BoxCollider2D objCol2d = _readySwapCol.GetComponent <BoxCollider2D>(); float playerRadiusY = player.GetComponent <BoxCollider2D>().bounds.size.y / 2f; float heightDiff = (_readySwapCol.GetComponent <BoxCollider2D>().bounds.size.y - playerRadiusY * 2f) / 2f; if (_swapThing.GetLeftX() < player.transform.position.x && _swapThing.GetRightX() > player.transform.position.x && _swapThing.GetLowerY() > player.transform.position.y && _swapThing.GetLowerY() < player.transform.position.y + playerRadiusY + 10f) { Vector3 temp = _readySwapCol.gameObject.transform.position; _readySwapCol.gameObject.transform.position = new Vector3( player.transform.position.x, player.transform.position.y - playerRadiusY + (_swapThing.GetUpperY() - _swapThing.GetLowerY()) / 2f, player.transform.position.z); player.transform.position = new Vector3( temp.x, _readySwapCol.gameObject.transform.position.y + playerRadiusY + (_swapThing.GetUpperY() - _swapThing.GetLowerY()) / 2f, player.transform.position.z); } else { _readySwapCol.gameObject.transform.position = new Vector3(posPlayer.x, _playerThing.GetLowerY() + playerRadiusY + heightDiff, posPlayer.z); player.transform.position = new Vector3(_posSwapThing.x, _posSwapThing.y - heightDiff, _posSwapThing.z); } TriggerInstanceEvent(_swapThing); swapped = true; }