I have been trying to implement a basic gun and i have got all the functionality enabled except the gun moving up and down. It rotates up and down but does not move with the camera. Here is a video of the problem:
Unity gun problem
Here is the gun code:
#pragma strict
var cameraObject : GameObject;
@HideInInspector
var targetXRotation : float;
@HideInInspector
var targetYRotation : float;
@HideInInspector
var targetXRotationV : float;
@HideInInspector
var targetYRotationV : float;
var rotateSpeed : float = 0.1;
var gunPosHeight : float = -0.1;
var gunPosSide : float = 0.65;
var gunPosZ : float = 1.12;
function Update () {
transform.position = cameraObject.transform.position + (Quaternion.Euler(0, targetYRotation, 0) * Vector3(gunPosSide, gunPosHeight, gunPosZ));
targetXRotation = Mathf.SmoothDamp(targetXRotation, cameraObject.GetComponent(mouseLook).xRotation, targetXRotationV, rotateSpeed);
targetYRotation = Mathf.SmoothDamp(targetYRotation, cameraObject.GetComponent(mouseLook).yRotation, targetYRotationV, rotateSpeed);
transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);
}