Can anyone help me fix this?
I really don’t get what you’re trying to accomplish by putting half of the variables in the Start() function. You need to put everything except
anim = GetComponent <Animator> ();
above Start() and it should work. You can’t declare something public in Start(). Variables declared in a function don’t exist outside that function.