I am making a fps game ( As learning ( Im still very new)) and I wanted a ADS script. I searched on the internet and found this:
var gun : Transform; //Drag you Gun transform into This
var curField = 60.0;
private var dampVelocity2 = 0.4;
var nextVector : Vector3; //Sights Transform
var curVector : Vector3; //Normal Transform
var curY = 234.8665; //Normal Rotation of Gun
var nextY = 230.7; //Rotation of Gun when looking down Sights
class weaponStats {
var curDamage : int; //Normal Weapon Damage
var nextDamage : int; //Sights Weapon Damage
var gunScript : String;
var mainCam : ads; //Change “CrossHair” to the name of the Script or GUITexture you use for your CrossHair
}
var speed : float = 0.1;
var stats : weaponStats;
function Update () {
//Smooth Changine Vield of View of Camera
var newField = Mathf.SmoothDamp(Camera.main.fieldOfView, curField, dampVelocity2, .3);
Camera.main.fieldOfView = newField;
if (Input.GetButton(“Fire2”)) { //“Fire2” is right click, can be changed
//adjust viewpoint and gun position
curField = 40;
//Rotating Gun to look down Camera Perfectly
transform.localRotation.eulerAngles = Vector3(0,nextY,0);
//slow down turning and movement speed
transform.root.GetComponent.movement.maxForwardSpeed = 2.5;
//Adjust Gun Damage
GetComponent(stats.gunScript).damage = stats.nextDamage;
stats.mainCam.enabled = false;
//Moving the gun
transform.localPosition = Vector3.Lerp(transform.localPosition,nextVector, 0.3);
} else {
//adjust viewpoint and gun position
curField = 60.0;
transform.localRotation.eulerAngles = Vector3(0,curY,0);
//speed up turning and movement speed
transform.root.GetComponent.movement.maxForwardSpeed = 10;
stats.mainCam.enabled = true;
GetComponent(stats.gunScript).damage = stats.curDamage;
transform.localPosition = Vector3.Lerp(transform.localPosition,curVector, speed);
}
}
Some things are changed rom orignal to fit in the setting of the game.
But there is 1 error left that I dont get:
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[ ] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[ ] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
ads.Update () (at Assets/scripts/ads.js:43
pls help…