// Update is called once per frame void Update() { _timer.IncrementTimer(Time.deltaTime); if (_timer.CheckTimer()) { UnstickBall(); _timer.ResetTimer(); } }
// Update is called once per frame public void FixedUpdate() { Rigidbody2D alienrb = alien.GetComponent <Rigidbody2D>(); var relativePosition = GetPlayersRelativeXPostion(alienrb); Debug.Log(IsRunningAway); var beingChased = CheckIfPlayerChasingCat(relativePosition, _lastPlayerPostion); if (beingChased) { StartRunningAway(); } if (IsRunningAway) { if (CheckIfFarEnoughAway(relativePosition)) { IsRunningAway = false; SetCatIdle(true); } else { if (IsOnFloor && rb.velocity.y == 0) { RunAwayFromPlayer(relativePosition); } } } else if (IsIdle) { if (_idleTimer.CheckTimer()) { SetCatIdle(false); } _idleTimer.IncrementTimer(Time.deltaTime); } else { if (Math.Abs(relativePosition) < spookDistance) { //cat prepares to pounce, is very slow _catSpeed = prowlingSpeed; } else if (Math.Abs(relativePosition) > spookDistance) { //cat is prowling normally _catSpeed = walkingSpeed; } if (Math.Abs(relativePosition) > pounceDistance) { HasPounced = false; MoveTowardsPlayer(relativePosition); } else if (!HasPounced) { if (!IsPreparing) { PrepareToPounce(); } else { if (_prepareTimer.CheckTimer()) { IsPreparing = false; Pounce(relativePosition); StartRunningAway(); } else { _prepareTimer.IncrementTimer(Time.deltaTime); } } } } anim.SetBool("IsMoving", !IsIdle && !IsRunningAway && !IsPreparing); _lastPlayerPostion = relativePosition; }