Gun script
varbeingHeld : boolean = false;
varoutsideBox : GameObject;
@HideInInspector
varcountToThrow : int = -1;
@HideInInspector
varplayerTransform : Transform;
@HideInInspector
varplayerMovementScript : PlayerMovementScript;
@HideInInspector
varcameraObject : GameObject;
@HideInInspector
vartargetXRotation : float;
@HideInInspector
vartargetYRotation : float;
@HideInInspector
vartargetXRotationV : float;
@HideInInspector
vartargetYRotationV : float;
varrotateSpeed : float = 0.3;
varholdHeight : float = -0.5;
varholdSide : float = 0.5;
varratioHipHold : float = 1;
varhipToAimSpeed : float = 0.1;
@HideInInspector
varratioToHipHoldV : float;
varaimRatio : float = 0.4;
varzoomAngle : float = 30;
varfireSpeed = 15;
@HideInInspector
varwaitTillNextFire : float = 0;
varbullet : GameObject;
varbulletSpawn : GameObject;
varshootAngleRandomizationAiming : float = 5;
varshootAngleRandomizationNotAiming: float = 15;
varrecoilAmount : float = 0.5;
varrecoilRecoverTime : float = 0.2;
@HideInInspector
varcurrentRecoilZPos : float;
@HideInInspector
varcurrentRecoilZPosV : float;
varbulletSound : GameObject;
varmuzzleFlash : GameObject;
vargunBobAmountX : float = 0.5;
vargunBobAmountY : float = 0.5;
@HideInInspector
varcurrentGunBobX : float;
@HideInInspector
varcurrentGunBobY : float;
functionAwake()
{
countToThrow = -1;
playerTransform = GameObject.FindWithTag(“Player”).transform;
playerMovementScript = GameObject.FindWithTag(“Player”).GetComponent(PlayerMovementScript);
cameraObject = GameObject.FindWithTag(“MainCamera”);
}
functionLateUpdate ()
{
if(beingHeld)
{
rigidbody.useGravity = false;
outsideBox.GetComponent(Collider).enable = false;
currentGunBobX = Mathf.Sin(cameraObject.GetComponent(MouseLook).headBobStepCounter) * gunBobAmountX * ratioHipHold;
currentGunBobY = Mathf.Cos(cameraObject.GetComponent(MouseLook).headBobStepCounter * 2) * gunBobAmountY * -1 * ratioHipHold;
varholdMuzzleFlash : GameObject;
varholdSound : GameObject;
if (Input.GetButton (“Fire1”))
{
if(waitTillNextFire <= 0)
{
if(bullet)
Instantiate (bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
if(bulletSound)
holdSound = Instantiate(bulletSound, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
if(muzzleFlash)
holdMuzzleFlash = Instantiate(muzzleFlash, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
targetXRotation += (Random.value - 0.5) * Mathf.Lerp(shootAngleRandomizationAiming, shootAngleRandomizationNotAiming, ratioHipHold);
targetYRotation += (Random.value - 0.5) * Mathf.Lerp(shootAngleRandomizationAiming, shootAngleRandomizationNotAiming, ratioHipHold);
currentRecoilZPos -= recoilAmount;
waitTillNextFire = 1;
}
}
waitTillNextFire -= Time.deltaTime * fireSpeed;
if(holdSound)
holdSound.transform.parent = transform;
if(holdMuzzleFlash)
holdMuzzleFlash.transform.parent = transform;
currentRecoilZPos = Mathf.SmoothDamp(currentRecoilZPos, 0, currentRecoilZPosV, recoilRecoverTime);
cameraObject.GetComponent(MouseLook).currentTargetCameraAngle = zoomAngle;
if(Input.GetButton(“Fire2”)){
cameraObject.GetComponent(MouseLook).currentAimRatio = aimRatio;
ratioHipHold = Mathf.SmoothDamp(ratioHipHold,0, ratioToHipHoldV, hipToAimSpeed);}
if(Input.GetButton(“Fire2”) == false){
cameraObject.GetComponent(MouseLook).currentAimRatio = 1;
ratioHipHold = Mathf.SmoothDamp(ratioHipHold,1, ratioToHipHoldV, hipToAimSpeed);}
transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0) * Vector3(holdSide * ratioHipHold + currentGunBobX, holdHeight * ratioHipHold + currentGunBobY, 0) + Quaternion.Euler(targetXRotation, targetYRotation,0) * Vector3(0,0,currentRecoilZPos));
targetXRotation = Mathf.SmoothDamp ( targetXRotation, cameraObject.GetComponent(MouseLook).xRotation, targetXRotationV, rotateSpeed);
targetYRotation = Mathf.SmoothDamp ( targetYRotation, cameraObject.GetComponent(MouseLook).yRotation, targetYRotationV, rotateSpeed);
transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);
}
if(!beingHeld)
{
rigidbody.useGravity = true;
outsideBox.GetComponent(Collider).enabled = true;
countToThrow -= 1;
if(countToThrow == 0)
rigidbody.AddRelativeForce(0, playerMovementScript.throwGunUpForce, playerMovementScript.throwGunForwardForce);
if(Vector3.Distance(transform.position, playerTransform.position) < playerMovementScript.distToPickUpGun && Input.GetButtonDown(“UseKey”) && playerMovementScript.waitFrameForSwitchGuns <= 0)
{
playerMovementScript.currentGun.GetComponent(GunScript).beingHeld = false;
playerMovementScript.currentGun.GetComponent(GunScript).countToThrow = 2;
playerMovementScript.currentGun = gameObject;
beingHeld = true;
targetYRotation = cameraObject.GetComponent(MouseLook).yRotation - 180;
playerMovementScript.waitFrameForSwitchGun = 2;
}
}
}
Is there anything wrong with script it is on line : 131