public void StartDash() { _dashRoutine = _timerCoroutineFactory.CreateTimer(.5f); _asyncTaskProcessor.Process(_dashRoutine, () => { _dashRoutine = null; }); }
void MovePlayer() { Vector3 movementDirection = GetMovementDirection(); if (_timerRoutine == null && _speedLevel < MaxSpeedLevel && movementDirection != Vector3.zero) { _timerRoutine = _timerCoroutineFactory.CreateTimer(_speedLevel + 1); _asyncTaskProcessor.Process(_timerRoutine, () => { _speedLevel++; Log.Debug("Speedlevel: {0}", _speedLevel); _timerRoutine = null; }); } if (movementDirection == Vector3.zero) { if (_walkingTimeout == null) { _walkingTimeout = _timerCoroutineFactory.CreateTimer(.25f); _asyncTaskProcessor.Process(_walkingTimeout, () => { _speedLevel = 1; if (_asyncTaskProcessor.IsProcessing(_timerRoutine)) { _asyncTaskProcessor.Cancel(_timerRoutine); _timerRoutine = null; _walkingTimeout = null; } }); } } else { if (_asyncTaskProcessor.IsProcessing(_walkingTimeout)) { _asyncTaskProcessor.Cancel(_walkingTimeout); _walkingTimeout = null; } } //Also if we have a nonzero velocity lets have the mesh kinda rotated forward //and bobbing as a little placeholder, more rotated per speed level var velocity = movementDirection * (InitialSpeed + (_speedLevel * SpeedMultiplier)); //Set direction and speed Rigidbody.velocity = Rigidbody.velocity .SetX(velocity.x) .SetZ(velocity.z); }