@Younes You might want to move your Invoke out of Update and into the actual MoveHand method such that the Invoke is repeated every time the function is called instead of every frame in Update. It could be overwriting the Invoke… In your Start, just call MoveHand() directly and then, because you’ve moved your Invoke into that method, it should call itself again after the delay.
If the aim is to add a delay to your move hand this is not the right way to do that. I would suggest you to do that but it also depends on the correct behaviour you need.
The small explanation is that you always call for Invoke and inside it you check for the fire button, this should be inverted. You might need to check for the fire button and then Invoke your function.
But there is an other issue,you might need to use the MoveTowards inside the update loop, then the Invoke method is not possible so I did a simple timer.
If you need more informations, feel free to ask.
public float moveSpeed = 1f;
public float delay = 0.5f;
public Vector3 targetPosition;
public bool move = false;
private float timer = 0.0f;
void Update()
{
if (Input.GetButton("Fire1"))
{
Vector3 mousePosition = Input.mousePosition;
mousePosition.z = transform.position.z - Camera.main.transform.position.z;
targetPosition = Camera.main.ScreenToWorldPoint(mousePosition);
move = true;
timer = 0.0f; // If you reset the timer here, the move stops and wait befor targeting the new position.
}
if (move)
{
timer += Time.deltaTime;
if (timer >= delay)
{
MoveHand();
}
}
}
void MoveHand()
{
float step = moveSpeed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, targetPosition, step);
if (transform.position == targetPosition)
{
move = false;
// timer = 0.0f; // If you reset the timer here, the move won't be delayed when clicking fast.
}
}