In the past I have done something that works but have always wondered if there was a more efficient (performance wise) way to do the same thing
gameObject.GetComponentInChildren(typeof(Camera), true).GetComponent<HeadBob>().bobbingSpeed = 0.04f;
gameObject.GetComponentInChildren(typeof(Camera), true).GetComponent<HeadBob>().bobbingAmount = 0.4f;
This is what I used in a small FPS project I’ve played around with in the past and worked alot on small little improvements to controls and responsiveness, in this case I had a script attached to the camera to make the “head” bob with movement, I made it so the ammount and speed would vary on the players movement state (crouching, walking slower, in the air), so whenever it would change I’d alter the variables in there and then reset them when movement returned to normal, in total I had to do this 8 times (counting enabling and disabling for whenever the player was in the air) for each of the variying states and then returning to normal.
Is there a better way to do this?