Unable to access function in different script

Hey there,
I have a gun script and a separate camera script. The gun script is supposed to pass a quaternion to the camera script, which is then added (in a function) to the camera’s rotation. However I get “component does not contain a reference for rotateCam()”

Here’s where I reference the camera script. It’s the mouseLook variable.

private Component mouseLook;

    // Use this for initialization
    void Start () {

        muzzle = transform.Find("Muzzle");
        anim = GetComponent<Animator>();
        cam = Camera.main.transform;

        mouseLook = cam.GetComponent<MouseLook>();

        aimHelper = cam.GetChild(0);
        hipHelper = cam.GetChild(1);


        anim.speed = animSpeed;

        rotRecoilOffset = Quaternion.Euler(0, 0, 0);
    }

Here’s the bad line (further down in the above script)

        mouseLook.rotateCam(ctargetRot);

And here’s the function in the camera script:

  public void RotateCam (Quaternion ctargetRotation)
    {
        var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));

        md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
        smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
        smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
        mouseLook += smoothV;

        mouseLook.y = Mathf.Clamp(mouseLook.y, minView, maxView);


        transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right) * ctargetRotation;
        character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
    }

Any ideas?

Make sure that the Camera has the MouseLook script.
Try to change

 private Component mouseLook;

to the:

 private MouseLook mouseLook;

Add the verification before the call:

Debug.Log("is it not equal to null? " + (mouseLook != null));
mouseLook.rotateCam(ctargetRot);

So that if we get “True” in the console than we can be sure that there is no problem with the reference.

Even if the problem exists, try to assign this component in the inspector. For example, change the following line:

[SerializeField] MouseLook mouseLook;

And assign MouseLook in the inspector. In case if it will not help, we should take a look at an another place in the code.