How can i stay in a function for a certain amount of time? I know about coroutines, so i should call coroutines every times for simple things? For example: when i press the key, at that time call function, which slowly move the character. The function fires instantly, that's why it doesn't work
void Update()
{
RaycastHit2D hitPlayer = Physics2D.Raycast(_tr.position,new Vector2(-1,0), _distance, LayerMask.GetMask("Player"));
if (hitPlayer.collider != null && Input.GetKeyDown(KeyCode.Space))
{
MovingToBox(hitPlayer);
}
}
private void MovingToBox(RaycastHit2D hitPlayer)
{
}