0.1 Frames Per Second on my FPS. HELP!

I am trying to make a CoD style FPS.
I have created the character with the First Person Controller in Unity4.
Here is the code:

 var gun : Transform;
 var nextPos = -0.3966427;
 var nextField = 40.0;
 var nextPos2 = -0.5313418;
 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.8139877;
        nextPos2 = -0.5313418;
        
        //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.3966427;
        nextPos2 = -0.5313418;
        
        //speed up turning and movement speed
        GetComponent("MouseLook").sensitivityX = 6;
        camera.main.GetComponent("MouseLook").sensitivityX = 6;
        camera.main.GetComponent("MouseLook").sensitivityY = 6;
    }
 }

Now… No matter what I do, even with the simple moving animations and having the quality settings at its lowest, the FPS just will not go above 0.1… Add that to after I modified the gun to be a child of the First Person Controller, and the amount of time it takes to process one thing is… Oh… About 5 minutes. This never happened before I put the gun into Unity. HELP. This lag is immense!

GetComponent(“TypeName”) is slower than GetComponent.{Type}, which is still slower than caching the value (var ml : MouseLook = camera.main.GetComponent.{Type}():wink:

I suspect that setting field-of-view every frame is what’s slowing you to zero though.

Edit:
UDN… stop eating my bracket characters. Replace the squigglies above with angle brackets and it’ll work. :stuck_out_tongue: