Rotating a bone via scripts

Goal: To be able to rotate bone in script. shoulder is the bone I’m trying to rotate.
Problem: No errors, but bone either
1.) doesn’t rotate in game
or 2.) mesh doesn’t move with bone

Here's my script:

shoulder is a Transform var

function PointToMouse(){
	if(shoulder){
		print("shoulder");
	}
	var playerPlane = new Plane(Vector3.forward,transform.position);
	var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	var hitdist = 0.0;
	if (playerPlane.Raycast (ray, hitdist)) {
	var targetPoint = ray.GetPoint(hitdist);}
	mouseVec = Vector3(targetPoint.x - transform.position.x,targetPoint.y - transform.position.y,0);
	zAngle = Vector3.Angle(mouseVec,Vector3(0,-1,0));
	if(zAngle>minZ && zAngle<maxZ){
	print(zAngle);
	shoulder.transform.localEulerAngles = Vector3(0,0,zAngle+270);
	}
}

It prints shoulder and prints zAngle and zAngle is correct.
Also, when shoulder is an Empty GameObject with a mesh as a child, the mesh will rotate. So I know the logic is right…

Any help?

Put the rotation code in LateUpdate. LateUpdate is called after the animation is applied, so you can override the animation movement. HOWEVER, if you do this the rotation cannot rely on the previous rotation of the bone, so no lerps or anything of that sort. You’ll get a jittering effect if you try to use a lerp with the previous rotation of the bone since the animation is still being applied before the next time the lerp is called.