Update Problem with Function inside Update()

I want my character to look at the enemy:

function UpdateSmoothedMovementDirection(){
...
var forward = lockOnTarget.TransformDirection(Vector3.forward);
...
}



Update(){

UpdateSmoothedMovementDirection();

if(Input.GetButton("LockOn")){
lockOn = true;
}
else{
lockOn = false;
}

It works very well this way, but when i put it this way:

(inside the UpdatedSmootedMovementDirection())
if(lockOn){
var forward = lockOnTarget.TransformDirection(Vector3.forward);
}

It doesn’t update it every frame like the first one. I have to pull my finger and press the button every time i want to update the direction of my character faces.

It won’t update every frame when you wrap it in the if(lockOn) because lockOn has to be true for it to work if you do that, so it is only true if you click the button. What are you trying to achieve by wrapping it with the if(lockOn)? If you want lockOn to remain true after clicking the button, then remove the else lockOn = false.

Also, you don’t need to precede your call to UpdateSmoothedMovementDirection(); in Update with the “function” name. I don’t believe that should even compile…