So I went for a Movement point system where the idea was to deactivate the movement script and activate options like combat later (used the spin for it now).
It kinda works. But it doesn’t update propperly and only when I manually reselect the unit. Not sure how to deal with this, thinking my script should be okey. I’ll place the full implimentation down here, and yes I could prob clean it up more and want to redo the enable and disable at some points when there will be more but 1 problem at a time
private int MovementAmount()
{
GridPosition targetGridPosition = LevelGrid.Instance.GetGridPosition(targetPosition);
GridPosition unitGridPosition = LevelGrid.Instance.GetGridPosition(transform.position);
GridPosition moveGridDistance = (targetGridPosition - unitGridPosition);
int movementAmount = Mathf.Abs(moveGridDistance.x) + Mathf.Abs(moveGridDistance.z);
return movementAmount;
}
private void NoMovementCheck()
{
maxMoveDistance = maxMoveDistance - distanceMoved;
if(maxMoveDistance <= 0 )
{
gameObject.GetComponent<MoveAction>().enabled = false;
gameObject.GetComponent<SpinAction>().enabled = true;
}
}
public int GetMovementLeft()
{
movementLeft = maxMoveDistance - totalDistanceMoved;
return movementLeft;
}
public override void TakeAction(GridPosition gridPosition, Action onActionComplete)
{
this.onActionComplete = onActionComplete;
isActive = true;
this.targetPosition = LevelGrid.Instance.GetWorldPosition(gridPosition);
distanceMoved = MovementAmount();
totalDistanceMoved += MovementAmount();
}
This is the base idea behind it
if (Vector3.Distance(targetPosition, transform.position) > stoppingDistance)
{
transform.position += moveDirection * Time.deltaTime * moveSpeed;
unitAnimator.SetBool("IsWalking", true);
}
else
{
unitAnimator.SetBool("IsWalking", false);
isActive = false;
onActionComplete();
NoMovementCheck();
}
I am atm checking for it at the end of my movement, but I could move that to onActionComplete at some point to make it cleaner.
When I check for the value in the UnitActionSystem under Update it only gives me the set starting value
private void NoMovementCheck()
{
Debug.Log(movementLeft);
if(movementLeft <= 0)
{
OnNoMovement?.Invoke(this, EventArgs.Empty);
}
}
moveAction = selectedUnit.GetMoveAction();
movementLeft = moveAction.GetMovementLeft();
So the debug keeps giving me the same number what means it doesn’t send to the UI to update the bottons. But i don’t see why it won’t.
There are no error messages or anything to help me out seeing what I do wrong.
any pointers are welcome ^^