Animator canceling a script (sway)

Hello, I create a sway script for my flashlight and attached it to the gameobject(flashlight).

Now the problem is that when I enable the animator in the gameobject(flashlight) the sway doesnt work,but when I disable it,it does work. This is the script :

#pragma strict

var flashLight : Transform;
var xSwayAmount : float = 0.1;
var ySwayAmount : float = 0.05;
var maxXAmount : float = 0.35;
var maxYAmount : float = 0.2;
private var vector3 : Vector3;
var smooth : float = 3.0;

function Start () {
	vector3 = flashLight.localPosition;

function Update () {
	var fx : float = -Input.GetAxis("Mouse X") * xSwayAmount;
	var fy : float = -Input.GetAxis("Mouse Y") * ySwayAmount;
	if(fx > maxXAmount)
	fx = maxXAmount;
	if(fx< -maxXAmount)
	fx = maxXAmount;
	if(fy > maxYAmount)
	fy = maxYAmount;
	if(fy < -maxYAmount)
	fy = -maxYAmount;
	var detection : Vector3 = new Vector3(vector3.x + fx, vector3.y + fy, vector3.z);
	flashLight.localPosition = Vector3.Lerp(flashLight.localPosition, detection, Time.deltaTime * smooth);

Has anyone got any idea why is this happening ? I need the animator to play my animations so I can’t just disable it.Thank you.

(just a guess) It might be because your animation overrides the sway?. You said you have sway script and animator in the same GameObject, try to create another GameObject, attach sway script to it, and make your current GameObject(flashlight) with animator as a child of that GameObject (reset Transform).Let me know how it works for you.

Create an empty gameobject (will be called parent) which holds your current gameobject. Move your animator to your parent object, sway can stay on your gameobject.

This should work.