- Home /
How can I stop the variable values reverting to its default values after being built?
I am using the FPS Constructor package by Dastardly Banana, the problem is that when I build the game - Web Player Version - the GunScript variables revert its values back to the initialized values, somehow it does not saved the values declared within the Unity Editor Inspector. Below is the part of the script where the variables are declared:
#pragma strict
#pragma downcast
/*
FPS Constructor - Weapons
Copyright� Dastardly Banana Productions 2011-2012
This script, and all others contained within the Dastardly Banana Weapons Package are licensed under the terms of the
Unity Asset Store End User License Agreement at http://download.unity3d.com/assetstore/customer-eula.pdf
For additional information contact us info@dastardlybanana.com.
*/
/////////////////////////// CHANGEABLE BY USER ///////////////////////////
/*These variables can be changed by external scripts when necessary.
*/
var myLight : Light;
////////// Accuracy Variables //////////
/*Kickback variables: Kickback is the visual motion of the camera when firing.
*/
var kickbackAngle : float; //Vertical kickback per shot (degrees)
var xKickbackFactor : float = .5; //Horizontal kickback per shot (percent of vertical)
var maxKickback : float = 15; //Maximum vertical kickback (degrees)
var kickbackAim : float;
var crouchKickbackMod : float = .6;
var proneKickbackMod : float = .35;
var moveKickbackMod : float = 1.3;
private var curKickback : float;
var recoilDelay : float = .11; //Delay between stopping firing and recoil decreasing
/*Spread variables: Spread (between 0 and 1) determines the accuracy of the weapon.
A spread of 0 means that the weapon will fire exactly towards the crosshair, and
a spread of 1 means that it will fire anywhere within 90 degrees of the crosshair.
*/
var standardSpread = .1; //default spread of this weapon
var maxSpread = .25; //Maximum spread of this weapon
var crouchSpreadModifier = .7; //When crouching, spread is multiplied by this
var proneSpreadModifier = .4; //When prone, spread is multiplied by this
var moveSpreadModifier = 1.5; //When walking, spread is multiplied by this
var standardSpreadRate = .05; //Standard increase in spread per shot
var aimSpreadRate = .01; //Increase in spread per shot when aiming
var aimSpread = .01; //Default spread when aiming
var spDecRate = .05; //Speed at which spread decreases when not firing
////////// Ammo variables //////////
var ammoLeft : float = 0; //Ammo left in the curent clip (ammo before next reload)
var ammoPerClip : int = 40; //Shots per clip
var ammoPerShot : int = 1; //Ammo used per shot
var clips : int = 20; //Number of spare clips (reloads) left
var maxClips : int = 20; //Maximum number of clips
var infiniteAmmo : boolean = false; //Does this gun deplete clips whe reoading?
enum ammoTypes {byClip, byBullet}
var ammoType : ammoTypes = ammoTypes.byClip; //Does this weapon conserve ammo when reloading? (e.g. if you reload after shooting one bullet, does it use a whole clip)
////////// Fire Variables //////////
var fireSound : AudioClip; //Sound that plays when firing
var fireVolume : float = 1;
var firePitch : float = 1;//Pitch of fire sound
var fireRate = 0.05; //Time in seconds between shots
var autoFire : boolean; //Is this weapon automatic (can you hold down the fre button?)
var fireAnim : boolean = false; //Does this weapon's fire animation scale to fit the fire rate (generally used for non-automatic weapons)
var delay : float = 0; //Delay between hitting fire button and actually firing (can be used to sync firing with animation)
var emptySound : AudioClip; //Sound that plays when firing
var emptyVolume : float = 1;
var emptyPitch : float = 1;//Pitch of fire sound
//Burst fire
//note: burst fire doesn't work well with automatic weapons
var burstFire : boolean = false; //does this wepon fire in bursts
var burstCount : int = 1; //shots per burst
var burstTime : float = .5; //time to fire full burst
////////// Reloading variables //////////
var reloadTime = 0.5;
var emptyReloadTime = .4;
var addOneBullet : boolean = false;
var waitforReload = 0.00;
/*Progressive Reload is a different kind of reloading where the reload is broken into stages.
The first stage initializes the animation to get to the second stage. The second stage represents
reloading one shot, and will repeat as many times as necessary to reach a full clip unless
interrupted. Then the third stage returns the weapon to its standrad position. This is useful
for weapons like shotguns that reload by shells.
*/
var progressiveReload : boolean = false; //Does this weapon use progressive reload?
var progressiveReset : boolean = false; //Does this weapon's ammo reset to 0 when starting a reload?
//(e.g. a revolver where the shells are discarded and replaced)
var reloadInTime = 0.5; //time in seconds for the first stage
var reloadOutTime = 0.5; //time in seconds for the third stage
//the time for the second stage is just reloadTime
////////// Gun-Specific Variables //////////
var range = 100.0; //Range of bullet raycast in meters
var force = 10.0; //Force of bullet
var damage = 5.0; //Damage per bullet
var shotCount : int = 6; //Bullets per shot
var penetrateVal : int = 1; //penetration level of bullet
/* Damage falloff allows raycast weapons to do less damage at long distances
*/
var hasFalloff : boolean = false; //Does this weapon use damage falloff?
var minFalloffDist : float = 10; //Distance at which falloff begins to take effect
var maxFalloffDist : float = 100; //Distance at which falloff stops (minumum damage)
var falloffCoefficient : float = 1; //Coefficient for multiplying damage
var falloffDistanceScale : float = 4; //Scaling value to change speed of falloff
////////// Launcher-Specific Variables //////////
var projectile : Rigidbody; //The object to launch. This can be anything, as long as it has a rigidbody.
var initialSpeed = 20.0; //Initial speed of projectile, applied forward
var projectileCount : int = 1; //Number of projectiles fired
var launchPosition : GameObject; //GameObject whose position the projectile is fired from (place this at the end of the weapon's barrel, generally)
////////// Tracer related variables //////////
/* Tracers are done using particle emitters.
*/
var tracer : GameObject; //Tracer object. Must have a particle emitter attached
var traceEvery : int = 0; //Activate a tracer evey x shots.
var simulateTime : float = .02; //How long to simulate tracer before it appears
var minDistForTracer : float = 2; //This isn't exposed, but can be tweaked if needed
////////// Sway //////////
var sway : boolean; //Does the weapon sway?
var moveSwayRate : Vector2 = Vector2(2.5, 5); //How fast does the weapon sway when walking? (xy)
var moveSwayAmplitude : Vector2 = Vector2(.04, .01); //How much does the weapon sway when walking? (xy)
var runSwayRate : Vector2 = Vector2(4.5, .9); //How fast does the weapon sway when sprinting? (xy)
var runAmplitude : Vector2 = Vector2(.04, .04); //How much does the weapon sway when sprinting? (xy)
var idleSwayRate : Vector2 = Vector2(2, 1); //How fast does the weapon sway when standing? (xy)
var idleAmplitude : Vector2 = Vector2(.002, .001); //How much does the weapon sway when standing? (xy)
////////// Secondary Weapons //////////
var secondaryWeapon : GunScript; //Gunscript of secondary weapon (additional weapon script on this object)
var secondaryInterrupt : boolean = false; //Can primary and secondary weapon interrupt each other's actions
var secondaryFire : boolean = false; //Is the secondary weapon fired with Mouse2?
var enterSecondaryTime : float = .5; //How long does it take to switch to secondary (animation)?
var exitSecondaryTime : float = .5; //How long does it take to switch from secondary (animation)?
////////// Charge weapon variables //////////
var minCharge : float = 0; //Minimum charge value at ahich the weapon can fire
var maxCharge : float = 10; // Maximum charge value the weapon can have
var chargeLevel : float = 0; //current charge level of the weapon
var forceFire : boolean = false; //Does this weapon have to fire when it hits max charge?
var chargeLoop : AudioClip; //Sound to play when charging
var chargeAuto : boolean = false; //Does the weapon automatically start charging again after a forced release?
//Specifically for hitscan charge weapons
var chargeCoefficient : float = 1.1; //Damage multiplier as charge increases
var additionalAmmoPerCharge : float = 0; //Ammo change as charge increases (add this per 1 charge level)
//////////Other variables//////////
var idleTime : float = 0; //Time in seconds that the player has been idle
var timeToIdle : float = 7; //Time in seconds of being idle which will cause the idle animation to play
var takeOutTime : float = .6; //Time to take out (switch to) weapon
var putAwayTime : float = .6; //Time to put away (switch from) weapon
//////////Z KickBack//////////
var useZKickBack : boolean = true; //Does this weapon use z kickback?
var kickBackZ : float = 2; //Rate of z kickback when firing
var zRetRate : float = 1; //rate of return from z when not firing
var maxZ : float = .3; //maximum z kickback
//////////Avoidance//////////
//Avoidance is by default handled globall by the Avoidance Component. This just overrides its values for this weapon.
var overrideAvoidance : boolean = false; //Does this weapon override global object avoidance values
var avoids : boolean = true;
var rot : Vector3;
var pos : Vector3;
var dist : float = 2;
var minDist : float = 1.5;
//Shell Ejection
var shellEjection : boolean = false; //Does this weapon use shell ejection?
var ejectorPosition : GameObject; //If it does, this gameobject provides the position where shells are instantiated
var ejectDelay : float = 0;
var shell : GameObject; //The shell prefab to instantiate
//Custom crosshair variables
var scale : boolean = false; //Does the crosshair scale with accuracy?
var crosshairObj : GameObject; //Crosshair object to use
var crosshairSize : float; //Default scale of the crosshair object
///////////////////////// END CHANGEABLE BY USER /////////////////////////
///////////////////////// Internal Variables /////////////////////////
/*These variables should not be modified directly, weither because it could compromise
the functioning of the package, or because changes will be overwritten.
*/
var gunActive : boolean = false; // Is the weapon currently selected & activated
//Status
private var interruptPutAway : boolean = false;
private var progressiveReloading : boolean = false;
var inDelay : boolean = false;
private var m_LastFrameShot = -1;
static var reloading : boolean = false;
var nextFireTime = 0.0;
static var takingOut : boolean = false;
static var puttingAway : boolean = false;
var secondaryActive : boolean = false;
static var crosshairSpread : float = 0;
private var shotSpread : float;
private var actualSpread : float;
private var spreadRate = .05;
var isPrimaryWeapon : boolean = true;
var aim : boolean = false;
var aim2 : boolean = false;
private var pReloadTime : float = 0;
private var stopReload : boolean = false;
private var startPosition : Vector3;
var gunDisplayed : boolean;
private var totalKickBack : float; //How far have we kicked back?
//Components
var ammo : AmmoDisplay;
var sprint : SprintDisplay;
var wepDis : WeaponDisplay;
static var mainCam : GameObject;
static var weaponCam : GameObject;
private var primaryWeapon : GunScript;
private var player : GameObject;
var aim1 : AimMode;
var mouseY : MouseLookDBJS;
var mouseX : MouseLookDBJS;
var reloadCancel : boolean = false;
////////// Spray //////////
/* Spray weapons are meant to be a simple solution for something that can now be done better with a
charge weapon.
*/
private var tempAmmo : float = 1;
var sprayOn : boolean = false;
var sprayObj : GameObject;
var sprayScript : SprayScript;
var deltaTimeCoefficient : float = 1;
var forceFalloffCoefficient : float = .99;
var loopSound : AudioClip;
var releaseSound : AudioClip;
var ammoPerSecond : float;
////////// Charge weapon variables //////////
var chargeWeapon : boolean = false; //Is this weapon a charge weapon?
var chargeReleased : boolean = false;
var chargeLocked : boolean = false;
//Gun Types
enum gunTypes {hitscan, launcher, melee, spray}
var gunType : gunTypes = gunTypes.hitscan;
//Melee
var hitBox : boolean = false;
//Tracer related variables
private var shotCountTracer : int = 0;
//Ammo Sharing
var sharesAmmo : boolean = false;
var shareLoadedAmmo : boolean = false;
var ammoSetUsed : int = 0;
var managerObject : GameObject;
var ammoManagerScript : AmmoManager;
//Effects
var effectsManager : EffectsManager;
var CM : CharacterMotorDB;
//Inspector only variables
var shotPropertiesFoldout : boolean = false;
var firePropertiesFoldout : boolean = false;
var accuracyFoldout : boolean = false;
var altFireFoldout : boolean = false;
var ammoReloadFoldout : boolean = false;
var audioVisualFoldout : boolean = false;
//Sway (Internal)
var swayStartTime : float = 0;
var swayRate : Vector2;
var swayAmplitude : Vector2;
var overwriteSway : boolean = false;
private var airborne : boolean = false;
Sound's like something to ask the banana people, unless they don't care if you post part of their scripts here so we can look at it and see what's going on.
Well, I sent them an email and no response yet, However I've spent a lot of time making this game from designing the game, texturing, scripting and it is just this bit that I am stuck.
Your answer
Follow this Question
Related Questions
Game-wide Variables 1 Answer
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
Why did my Transform Component stop using degrees for rotation 2 Answers
Unity 2017..1.1f1 (64bit) building error 0 Answers
Can someone tell me what's the problem with my JDK? 1 Answer