So I added two variables and two lines of code to my script, and now it does not update it in the inspector or when I run the game. Can someone please help. I feel like I am missing something or added something extra in my script. The two variables are the recoilX and Y. And the two lines are the ones that increase the rotationX and Y by a random number * 5. Help! Thanks!
#pragma strict
//Variables
var recoilX: float = 10;
var recoilY: float = 10;
var rotationSpeed: float = 0.03;
var holdHeight: float = -0.23;
var holdSide: float = 0.27;
var holdDistance: float = 0.52;
var cameraObject: GameObject;
var ratioHipToHold: float = 1;
var hipToAimSpeed: float = 0.1;
@HideInInspector
var ratioHipToHoldV: float;
@HideInInspector
var rotationTargetX: float;
@HideInInspector
var rotationTargetY: float;
@HideInInspector
var rotationTargetXVelocity: float;
@HideInInspector
var rotationTargetYVelocity: float;
var walkScript: PlayerMovementScript;
var aimingSensitivityGS: float = 0.25;
var aimingWalkSpeedGS: float = 0.5;
var aimFOV: float = 1;
@HideInInspector
var aimFOVV: float;
@HideInInspector
var currentFOV: float = 60;
var defaultFOV:float = 60;
@HideInInspector
var positionTargetVelocity: Vector3;
var positionMoveSpeed: float = .1;
var rateOfFire: float = 18;
@HideInInspector
var fireDelay: float = 0;
var bullet: GameObject;
var bulletSpawn: GameObject;
var ammo: int = 15;
var spreadHipFire: float = 5;
var spreadIronSight: float = 3;
function Start () {
}
function Update ()
{
currentFOV = camera.main.fieldOfView;
//Spawns the bullet
if(Input.GetButtonDown("Fire1"))
{
if(fireDelay <= 0 && ammo > 0)
{
if (bullet)
{
Instantiate(bullet,bulletSpawn.transform.position, bulletSpawn.transform.rotation);
fireDelay = 1;
cameraObject.GetComponent(MouseLookScript).rotationX += (Random.value * 5);
cameraObject.GetComponent(MouseLookScript).rotationY += (Random.value * 5);
rotationTargetY +=(Random.value - 0.5) * Mathf.Lerp(spreadIronSight, spreadHipFire, ratioHipToHold);
rotationTargetX +=(Random.value - 0.5) * Mathf.Lerp(spreadIronSight, spreadHipFire, ratioHipToHold);
ammo -= 1;
}
}
}
//Reloads the weapon
if(Input.GetButtonDown("Reload"))
{
ammo = 15;
}
fireDelay -= Time.deltaTime * rateOfFire;
//Enables/disables iron sights. Also changes look sensitivity and walk speed
if(Input.GetButton("Fire2"))
{
ratioHipToHold = Mathf.SmoothDamp(ratioHipToHold, 0, ratioHipToHoldV, hipToAimSpeed);
cameraObject.GetComponent(MouseLookScript).aimingSensitivity = aimingSensitivityGS;
walkScript.aimingWalkSpeed = aimingWalkSpeedGS;
camera.main.fieldOfView = Mathf.SmoothDamp(currentFOV, aimFOV, aimFOVV, hipToAimSpeed);
}
else
{
ratioHipToHold = Mathf.SmoothDamp(ratioHipToHold, 1, ratioHipToHoldV, hipToAimSpeed);
lookScript.aimingSensitivity = 1;
walkScript.aimingWalkSpeed = 1;
if(currentFOV != defaultFOV)
{
camera.main.fieldOfView = Mathf.SmoothDamp(currentFOV, defaultFOV, aimFOVV, hipToAimSpeed);
}
}
//Sets position
transform.position = cameraObject.transform.position + (Quaternion.Euler(rotationTargetX,rotationTargetY,0) * Vector3(holdSide * ratioHipToHold, holdHeight *ratioHipToHold, holdDistance));
//Rotates the gun with the camera
rotationTargetX = Mathf.SmoothDamp(rotationTargetX, cameraObject.GetComponent(MouseLookScript).rotationX, rotationTargetXVelocity, rotationSpeed);
rotationTargetY = Mathf.SmoothDamp(rotationTargetY, cameraObject.GetComponent(MouseLookScript).rotationY, rotationTargetYVelocity, rotationSpeed);
transform.rotation = Quaternion.Euler(rotationTargetX * -1, rotationTargetY - 180, 0);
}
//transform.position = cameraObject.transform.position + (Quaternion.Euler(rotationTargetX,rotationTargetY,0) * Vector3(holdSide * ratioHipToHold, holdHeight *ratioHipToHold, holdDistance));