JAVASCRIPT SCRIPTING ERROR IN UNITY 5 PLEASE HELP

Hi When using this script in unity 5

 var gun : Transform;
var nextPos = -0.2393376;
var nextField = 40.0;
var nextPos2 = -0.3882463;
var dampVelocity = 0.4;
var dampVelocity2 = 0.4;
var dampVelocity3 = 0.4;
function Update () {
    var newPos = Mathf.SmoothDamp(gun.transform.localPosition.x, nextPos, dampVelocity, .3);
    var newField = Mathf.SmoothDamp(Camera.main.fieldOfView, nextField, dampVelocity2, .3);
    var newPos2 = Mathf.SmoothDamp(gun.transform.localPosition.y, nextPos2, dampVelocity3, .3);
   
    gun.transform.localPosition.x = newPos;
    gun.transform.localPosition.y = newPos2;
    Camera.main.fieldOfView = newField;
   
    if (Input.GetButton("Fire2")) {
        //adjust viewpoint and gun position
        nextField = 40.0;
        nextPos = -0.5241224;
        nextPos2 = -0.349839;
       
        //slow down turning and movement speed
        GetComponent("MouseLook").sensitivityX = 2;
        camera.main.GetComponent("MouseLook").sensitivityX = 2;
        camera.main.GetComponent("MouseLook").sensitivityY = 2;
    } else {
        //adjust viewpoint and gun position
        nextField = 60.0;
        nextPos = -0.2393376;
        nextPos2 = -0.3882463;
       
        //speed up turning and movement speed
        GetComponent("MouseLook").sensitivityX = 6;
        camera.main.GetComponent("MouseLook").sensitivityX = 6;
        camera.main.GetComponent("MouseLook").sensitivityY = 6;
    }
}

I Get this error

  • AimDownSights.js(26,9): BCE0144: ‘UnityEngine.Component.camera’ is obsolete. Property camera has been deprecated. Use GetComponent() instead. (UnityUpgradable)

AimDownSights.js(27,9): BCE0144: ‘UnityEngine.Component.camera’ is obsolete. Property camera has been deprecated. Use GetComponent() instead. (UnityUpgradable)

AimDownSights.js(27,9): BCE0144: ‘UnityEngine.Component.camera’ is obsolete. Property camera has been deprecated. Use GetComponent() instead. (UnityUpgradable)

AimDownSights.js(37,9): BCE0144: ‘UnityEngine.Component.camera’ is obsolete. Property camera has been deprecated. Use GetComponent() instead. (UnityUpgradable)

You need to confirm the prompt to update your code.

2655728--187217--Prompt.jpg

Auto-Updated code:

var gun : Transform;
var nextPos = -0.2393376;
var nextField = 40.0;
var nextPos2 = -0.3882463;
var dampVelocity = 0.4;
var dampVelocity2 = 0.4;
var dampVelocity3 = 0.4;

function Update() {
    var newPos = Mathf.SmoothDamp(gun.transform.localPosition.x, nextPos, dampVelocity, .3);
    var newField = Mathf.SmoothDamp(Camera.main.fieldOfView, nextField, dampVelocity2, .3);
    var newPos2 = Mathf.SmoothDamp(gun.transform.localPosition.y, nextPos2, dampVelocity3, .3);

    gun.transform.localPosition.x = newPos;
    gun.transform.localPosition.y = newPos2;
    Camera.main.fieldOfView = newField;

    if (Input.GetButton("Fire2")) {
        //adjust viewpoint and gun position
        nextField = 40.0;
        nextPos = -0.5241224;
        nextPos2 = -0.349839;

        //slow down turning and movement speed
        GetComponent("MouseLook").sensitivityX = 2;
        GetComponent. < Camera > ().main.GetComponent("MouseLook").sensitivityX = 2;
        GetComponent. < Camera > ().main.GetComponent("MouseLook").sensitivityY = 2;
    } else {
        //adjust viewpoint and gun position
        nextField = 60.0;
        nextPos = -0.2393376;
        nextPos2 = -0.3882463;

        //speed up turning and movement speed
        GetComponent("MouseLook").sensitivityX = 6;
        GetComponent. < Camera > ().main.GetComponent("MouseLook").sensitivityX = 6;
        GetComponent. < Camera > ().main.GetComponent("MouseLook").sensitivityY = 6;
    }
}

It never asked me to upgrade, I’ll try that code!

Thanks! Worked! Saved meee! good work bro

you are welcome;)