internal void GetAttacked() { ServiceLocator.GetDebugProvider().Log("attacked"); hp.ReduceMaximumHealth(ruleSet.MONSTER_DAMAGE); Screenshake.INSTANCE.DoScreenshake(); // if (hp.GetCurrentHealth() > 0) // { if (fire) { if (jump) { jump.DoJump(1, 1f); } isBurning = true; fireLight.enabled = true; fire.Play(); Invoke("StopFire", 2f); } if (hp.GetCurrentHealth() <= 0) { GameManager.INSTANCE.GameOver(); } else { ServiceLocator.GetAudioProvider().PlaySoundEvent("Burning"); ServiceLocator.GetAudioProvider().PlaySoundEvent("TakeHit"); } // } }
void Update() { if (transform.position.y < yBorder) { Respawn(); } // Смотрим в какой стороне кот var delta = target.transform.position.x - transform.position.x; if (Mathf.Abs(delta) > 2) { direction = (delta > 0 ? 1f : -1f); } if (jumpCooldown > 0f) { currentJumpCooldown -= Time.deltaTime; } Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position + new Vector3(direction, -0.5f, 0), raduis); bool isCollided = false; foreach (Collider2D item in colliders) { if (item.gameObject == ground) { isCollided = true; } } jump.holdJump = isCollided; if (isCollided) { if (currentJumpCooldown <= 0f) { currentJumpCooldown = jumpCooldown; jump.DoJump(); } } sprite.flipX = direction < 0; // Двигаемя Vector2 movement = new Vector2(speed, 0); transform.Translate(direction * movement * Time.deltaTime); }
public void OnTriggerEnter(Collider other) { if (!other.gameObject.CompareTag("Agent")) { return; } Agent agent = other.GetComponent <Agent>(); Jump jump = other.GetComponent <Jump>(); if (agent == null || jump == null) { return; } Vector3 originPos = transform.position; Vector3 targetPos = landingLocation.transform.position; jump.Isolate(true); jump.jumpPoint = new JumpPoint(originPos, targetPos); jump.DoJump(); }
/// Applies an action to the character. private void ApplyAction() { // Apply the movement affected by the player input. switch (actualAction) { case CharacterActions.Jump: jump.DoJump(jumpTransform, playerParameters.jumpHeight); if (IsActionComplete(Globals.CH_JUMP_DURATION)) { jump.ResetJump(jumpTransform); actualAction = CharacterActions.None; } break; case CharacterActions.Slide: if (IsActionComplete(Globals.CH_SLIDE_DURATION)) { playerCollider.center = new Vector3(playerCollider.center.x, Globals.CH_COLLIDER_NORMAL_Y_POS, playerCollider.center.z); playerCollider.height = Globals.CH_COLLIDER_NORMAL_HEIGHT; actualAction = CharacterActions.None; } break; case CharacterActions.Dodge: dodge.MoveToDodge(myTransform); // Check when the dodge movement ends. if (dodge.IsDodgeComplete()) { actualAction = CharacterActions.None; } break; default: break; } movement.Move(myTransform, ref actualSpeed, playerParameters.acceleration, actualSpeed < playerParameters.maxSpeed); }
private void Update() { if (!isMobile) { dir = Input.GetAxis("Horizontal"); if (Input.GetButtonDown("Jump")) { jump.DoJump(); } jump.holdJump = Input.GetButton("Jump"); // TODO } if (dir != 0) { Run(); } if (transform.position.y < yBorder) { Die(); } if (Time.time - damageTime > 5f) { isDamaged = false; } if (Time.time - birdEatedTime > 5f) { isBirdEated = false; UpdateSpeed(); } if (transform.position.x > end.position.x) { Result.Psss(); } }