AimDownSights script not working
Hi Guys! I am trying to add the Aim Down Sights to my FPS game. The script that I use is this:
  var gun : Transform;
  var nextPos = 0.0;
  var nextField = 40.0;
  var nextPos2 = -0.2;
  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.0;
         nextPos2 = -0.2;
  
         //slow down turning and movement speed
         GetComponent(FPSWalker).speed = 1.5;
         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.5;
         nextPos2 = -0.4;
  
         //speed up turning and movement speed
         GetComponent(FPSWalker).speed = 6;
         GetComponent("MouseLook").sensitivityX = 6;
         camera.main.GetComponent("MouseLook").sensitivityX = 6;
         camera.main.GetComponent("MouseLook").sensitivityY = 6;
     }
  }
I attach this script to the First Person Controller and drag my gun into the scripts gun object. But when I play the game it gives me two errors: 1) NullReferenceException: Object reference not set to an instance of an object 1.Update () (at Assets/Gun Related/Scripts/1.js:36)
2)CompareApproximately (det, 1.0F, .005f) UnityEditor.SceneView:OnEnable() UnityEditorInternal.InternalEditorUtility:LoadSerializedFileAndForget(String) UnityEditor.EditorApplicationLayout:SetPausemodeLayout()
Please tell me how to fix it I am really poor at scripting.
Your answer
 
 
             Follow this Question
Related Questions
BasicFPS controller "Can not be loaded" 0 Answers
UNITY shooting script does nothing 1 Answer
sound buzzing enemy dies 1 Answer
How to set gamobjects active on network? 0 Answers
Add sound to camera for when an object is destroyed 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                