protected override void move() { if (Position2D != targetPos) { float updateSpeed = (isSearching ? followSpeed : speed) * Time.fixedDeltaTime; if (indexDest != -1) { if (indexDest >= path.Length) { indexDest = path.Length - 1; } movement = path[indexDest] - Position2D; dir = DirectionEnumMethods.GetDirection(movement); spriteManager.ActualDir = dir; if (movement.magnitude <= updateSpeed) { //transform.position = new Vector3(path[indexDest].x, path[indexDest].y, transform.position.z); indexDest++; if (indexDest == path.Length) { indexDest = -1; isMoving = false; if (isSearching) { isSearching = false; } spriteManager.stop(); } } movement.Normalize(); rb.MovePosition(rb.position + movement * updateSpeed); //else //{ // movement.Normalize(); // transform.position = transform.position + new Vector3(movement.x, movement.y, 0) * updateSpeed; //} } if (!spriteManager.update) { spriteManager.start(); } spriteManager.Update(); } else if (spriteManager.update) { spriteManager.stop(); } }
// Update is called once per frame void Update() { if (!Menu.inGame || Inventory.Instance.IsInInventory()) { if (spriteManager.update) { clipWalk.Stop(); spriteManager.stop(); isMoving = false; } return; } if (!isLose && !combatComponent.isDead) { if (Input.GetButtonDown("Interact") && interactableItem != null) { //interact = true; if (interactableItem.interact(this)) { if (interactableItem != null) { interactableItem.CanBeInteract(false); interactableItem = null; } } //interact = false; } else if (Input.GetButtonDown("Fight") && combatComponent.CanAttack) { combatComponent.Attack(dir); bloodLustComponent.addBloodLust(attackBloodLustCost); if (spriteManager.update) { clipWalk.Stop(); spriteManager.stop(); //isMoving = false; } } else if (!combatComponent.isAttacking) { if (checkLevel()) { DisplayLoseScreen("Your Lycanthropy level As reach 100% you Lose "); } else { float inputX = Input.GetAxis("Horizontal"); float inputY = Input.GetAxis("Vertical"); movement = new Vector3(inputX, inputY).normalized; if (movement.magnitude > 0) { isMoving = true; dir = DirectionEnumMethods.GetDirection(movement); spriteManager.ActualDir = dir; float run = Input.GetAxis("Run"); //transform.position = transform.position + movement * Time.deltaTime * (((1 - run) * speed) + (run * runSpeed)); movement *= /* Time.deltaTime * */ (((1 - run) * speed) + (run * runSpeed)); if (run == 1) { bloodLustComponent.addBloodLust(runBloodLustCost * Time.deltaTime); } if (!spriteManager.update) { isMoving = true; spriteManager.start(); clipWalk.Play(); } spriteManager.Update(); } else if (spriteManager.update) { isMoving = false; clipWalk.Stop(); spriteManager.stop(); } } } } else { if (!isLose) { DisplayLoseScreen("Your life as reach 0"); } } }