private void FixedUpdate()
    {
        currentPosition = heroTransform.position;

        if (Mathf.Ceil(currentPosition.x) != Mathf.Ceil(targetPosition.x) ||
            Mathf.Ceil(currentPosition.y) != Mathf.Ceil(targetPosition.y))
        {
            Vector2 roundedTarget  = new Vector2(Mathf.RoundToInt(targetPosition.x), Mathf.RoundToInt(targetPosition.y));
            Vector2 roundedCurrent = new Vector2(Mathf.RoundToInt(currentPosition.x), Mathf.RoundToInt(currentPosition.y));

            Vector2 directionMovement = (roundedTarget - roundedCurrent).normalized;

            directionMovement.x = Mathf.Round(directionMovement.x);
            directionMovement.y = Mathf.Round(directionMovement.y);

            Vector2 movement    = directionMovement * movementSpeed;
            Vector2 newPosition = currentPosition + movement * Time.fixedDeltaTime;

            heroRigidbody.MovePosition(newPosition);
            characterAnimatorScript.AnimateRun(targetPosition);
        }
        else
        {
            if (pathFinding.path != null && pathFinding.path.Count > 0)
            {
                targetPosition = pathFinding.path.Pop();
            }
            characterAnimatorScript.AnimateStatic();

            heroPositionAndState.Position     = targetPosition;
            heroPositionAndState.IsAtPosition = true;

            placeSelectEvent.Raise(heroPositionAndState);
        }
    }
Beispiel #2
0
        /// <summary>
        /// Fires an employee. The employee will be removed from hiredEmployees and placed in exEmployees.
        /// </summary>
        /// <param name="emp"></param>
        public void FireEmployee(Employee emp)
        {
            FireEmployeeData(emp.EmployeeData);
            Destroy(emp.gameObject);
            var employeeGui = EmployeeHiredContent
                              .GetComponentsInChildren <HiredEmployeeUiBuilder>().First(e => e.emp == emp).gameObject;

            Destroy(employeeGui);
            EmployeeFired.Raise(emp);
        }
Beispiel #3
0
        /// <summary>
        /// Hires the specified employee.
        /// If the employee does not exist in the employeesForHire List this method will do nothing;
        /// </summary>
        /// <param name="empData">The employee to hire.</param>
        public void HireEmployee(EmployeeData empData, GameObject employeeForHireGui)
        {
            if (!data.employeesForHire.Contains(empData))
            {
                return;
            }

            RemoveEmployeeForHire(empData);
            AddHiredEmployee(empData);
            if (HiredEmployees >= MaxNumberOfHiredEmployees)
            {
                data.employeesForHire.ForEach(emp =>
                                              EmployeeToGuiMap[emp].GetComponent <HireableEmployeeUiBuilder>().DisableHireButton(true));
            }
            EmployeesNumChangedEvent.Raise(data.hiredEmployees.Count);

            if (!data.FirstEmployeeHired)
            {
                data.FirstEmployeeHired = true;
                FirstEmployeeHired.Raise(GetEmployee(empData));
            }
        }