// Update is called once per frame void Update() { if (Physics2D.OverlapCircle(checkPlayer.position, checkRadius, playerLayers)) { playerHeart.TakeDamage(valueDamage); } }
// Update is called once per frame void Update() { timeLeft -= Time.deltaTime; if (timeLeft < 0) { DestroyBall(); } transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime); if (Physics2D.OverlapCircle(attackPoint.position, attackRange, PlayerLayers)) { playerHeart.TakeDamage(valueDamage); DestroyBall(); } else if (Physics2D.OverlapCircle(attackPoint.position, attackRange, GroundLayers)) { DestroyBall(); } }
void FixedUpdate() { float p = playerMain.transform.position.x; float e = gameObject.transform.position.x; float distance = Vector2.Distance(transform.position, player.position); float distanceCeiling = Vector2.Distance(transform.position, checkCeiling.position); float distanceHand = Vector2.Distance(transform.position, checkHand.position); //print(distanceCeiling); if ((distance < agroRange) && (_moveState == MoveState.Live)) { ChasePlayer(); } else if (_moveState == MoveState.Live) { StopChasePlayer(); } if ((distanceCeiling < 0.35f || distanceHand < 0.20f || distanceHand < 0.20f) && (_moveState == MoveState.Live)) { playerHeart.TakeDamage(valueDamage); Die(); } if (e - p > 0 && !facingRight) { // Меняем направление. Swap(); } // В противном случае, если input перемещает игрока влево, // а игрок направлен вправо ... else if (e - p < 0 && facingRight) { // Меняем направление. Swap(); } }