The type 'UnityEngine.Quaternion' does not have a visible contructor(BCE0024)

I’m getting this error and I really don’t know what to do, I’m trying to make the weapon sway when I move around.

public var defaultPosition : Quaternion;
var swayAmount : float = 5.0;
var swayX;
var swayY;
var swaySpeed : float = 5.0;
var newPos : Quaternion;
var gun : GameObject;

function Start () {
	defaultPosition = transform.localRotation;
}

function Update () {
	swayX = Input.GetAxis("Mouse X") * Time.deltaTime * swayAmount;
	swayY = Input.GetAxis("Mouse Y") * Time.deltaTime * swayAmount;
	newPos = new Quaternion(defaultPosition.x - swayX, defaultPosition.y - swayY, defaultPosition.z);
	gun.transform.localRotation = Quaternion.Lerp(gun.defaultPosition, newPos, swaySpeed * Time.deltaTime);
}

Thanks.

Is your newPos actually meant to be a quaternion? That’s what is causing the problem: you’re defining a Quaternion using the constructor with only 3 variables x, y, z. You also need a fourth variable (w) to call it. Generally speaking though, you rarely need/use the constructor. See the doc for more details

newPos = Quaternion.Eular(defaultPosition.x - swayX, defaultPosition.y - swayY, defaultPosition.z);