Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Assistance on gun ammo!

Discussion in 'Scripting' started by xXdragon15Xx, Aug 7, 2014.

  1. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    Hello, I'm trying to attach this script onto my guns As a new script, but when I join ingame and test them. They have their own set clips, ammo, damage, fire rate.. I cannot find ANY script that may be causing this.. and why wont this change my guns if Its attached as a script..?

    Code (JavaScript):
    1. enum FireMode { semi, auto }
    2. var Mode = FireMode.semi;
    3.  
    4.     var soundFire : AudioClip;
    5.     var soundReload : AudioClip;
    6.     var soundEmpty : AudioClip;
    7.     var soundDraw : AudioClip;
    8.     var weaponAnim : GameObject;
    9.  
    10.     var Concrete : GameObject;
    11.     var Wood : GameObject;
    12.     var Metal : GameObject;
    13.     var Dirt : GameObject;
    14.     var Blood : GameObject;
    15.     var untagged : GameObject;
    16.  
    17.     var layerMask : LayerMask;
    18.     var muzzleFlash : Renderer;
    19.     var muzzleLight : Light;
    20.  
    21.     var damage : int = 50;
    22.     var bulletsPerMag : int = 50;
    23.     var magazines : int = 5;
    24.     var reloadTime = 2;
    25.     var drawTime = 1.0;
    26.     private var bulletsLeft = 0;
    27.     var fireRate : float = 0.1;
    28.     var range : float = 1000;
    29.     var force : float = 500;
    30.  
    31.     //Weapon accuracy
    32.     private var baseInaccuracy : float;
    33.     var inaccuracyIncreaseOverTime : float = 0.01;
    34.     var inaccuracyDecreaseOverTime : float = 0.5;
    35.     private var maximumInaccuracy : float;
    36.     private var triggerTime : float = 0.05;
    37.     var baseInaccuracyAIM : float = 0.005;
    38.     var baseInaccuracyHIP : float = 1.5;
    39.     var maxInaccuracyHIP : float = 5.0;
    40.     var maxInaccuracyAIM : float = 1.0;
    41.  
    42.     //Aiming
    43.     var hipPosition : Vector3;
    44.     var aimPosition : Vector3;
    45.     private var aiming : boolean;
    46.     private var curVect : Vector3;
    47.     var aimSpeed : float = 0.25;
    48.     var scopeTime : float;
    49.     private var inScope : boolean = false;
    50.     var scopeTexture : Texture;
    51.  
    52.     //Field Of View
    53.     var zoomSpeed : float = 0.5;
    54.     var FOV : int = 40;
    55.  
    56.     //KickBack
    57.     var kickGO : Transform;
    58.     var kickUpside : float = 0.5;
    59.     var kickSideways : float = 0.5;
    60.  
    61.     //GUI
    62.     var mySkin : GUISkin;
    63.  
    64.     private var m_LastFrameShot : int = -1;
    65.     private var nextFireTime = 0.0;
    66.     private var reloading : boolean;
    67.     private var draw : boolean;
    68.     var weaponCamera : GameObject;
    69.     var mainCamera : GameObject;
    70.     private var player : GameObject;
    71.     @HideInInspector
    72.     var selected : boolean = false;
    73.     private var isFiring : boolean = false;
    74.     private var playing : boolean = false;
    75.  
    76.         //Crosshair Textures
    77.     var crosshairFirstModeHorizontal : Texture2D;
    78.     var crosshairFirstModeVertical : Texture2D;
    79.     private var adjustMaxCroshairSize : float = 6.0;
    80.  
    81. function Start(){
    82.     weaponCamera = GameObject.FindWithTag("WeaponCamera");
    83.     mainCamera = GameObject.FindWithTag("MainCamera");
    84.     player = GameObject.FindWithTag("Player");
    85.     muzzleFlash.enabled = false;
    86.     muzzleLight.enabled = false;
    87.     bulletsLeft = bulletsPerMag;
    88.     aiming = false;
    89. }
    90.  
    91.  
    92. function Update() {
    93.     if(selected){
    94.  
    95.         if(Input.GetButtonDown ("Fire")){
    96.             if(Mode == FireMode.semi){
    97.                 fireSniper();
    98.             }
    99.        
    100.             if(bulletsLeft > 0)
    101.             isFiring = true;
    102.         }
    103.    
    104.         if (Input.GetButton ("Fire")){
    105.             if(Mode == FireMode.auto){
    106.                 fireSniper();
    107.                 if(bulletsLeft > 0)
    108.                 isFiring = true;
    109.             }
    110.         }
    111.    
    112.         if (Input.GetButtonDown ("Reload")){
    113.             Reload();
    114.         }
    115.  
    116.         if (Input.GetButton("Fire2") && !Input.GetButton("Run") && !reloading){    
    117.             if (!aiming){
    118.                 aiming = true;
    119.                 curVect = aimPosition - transform.localPosition;
    120.                 scopeTime = Time.time + aimSpeed;
    121.             }
    122.  
    123.             if (transform.localPosition != aimPosition && aiming){
    124.                 if(Mathf.Abs(Vector3.Distance(transform.localPosition , aimPosition)) < curVect.magnitude/aimSpeed * Time.deltaTime){
    125.                     transform.localPosition = aimPosition;
    126.                 } else {
    127.                     transform.localPosition += curVect/aimSpeed * Time.deltaTime;                
    128.                 }
    129.             }
    130.        
    131.             if (Time.time >= scopeTime && !inScope){
    132.                 inScope = true;
    133.                 var gos = GetComponentsInChildren(Renderer);
    134.                     for( var go : Renderer in gos){
    135.                         go.renderer.enabled = false;
    136.                     }
    137.                 }
    138.  
    139.         } else {
    140.             if (aiming){
    141.                 aiming = false;
    142.                 inScope = false;
    143.                 curVect= hipPosition-transform.localPosition;
    144.                 var go = GetComponentsInChildren(Renderer);
    145.                 for( var g : Renderer in go){
    146.                 if (g.name != "muzzle_flash")
    147.                     g.renderer.enabled = true;
    148.                 }
    149.             }
    150.        
    151.             if(Mathf.Abs(Vector3.Distance(transform.localPosition , hipPosition)) < curVect.magnitude/aimSpeed*Time.deltaTime){
    152.                 transform.localPosition = hipPosition;
    153.             }else{
    154.                 transform.localPosition += curVect/aimSpeed*Time.deltaTime;
    155.             }
    156.         }
    157.    
    158.         if(inScope){
    159.             maximumInaccuracy = maxInaccuracyAIM;
    160.             baseInaccuracy = baseInaccuracyAIM;
    161.             mainCamera.camera.fieldOfView -= FOV * Time.deltaTime/zoomSpeed;
    162.             if(mainCamera.camera.fieldOfView < FOV){
    163.                 mainCamera.camera.fieldOfView = FOV;
    164.             }
    165.             weaponCamera.camera.fieldOfView -= 40 * Time.deltaTime/zoomSpeed;
    166.             if(weaponCamera.camera.fieldOfView < 40){
    167.                 weaponCamera.camera.fieldOfView = 40;
    168.             }
    169.         }else{
    170.             maximumInaccuracy = maxInaccuracyHIP;
    171.             baseInaccuracy = baseInaccuracyHIP;
    172.             mainCamera.camera.fieldOfView += 60 * Time.deltaTime/0.2;
    173.             if(mainCamera.camera.fieldOfView > 60){
    174.                 mainCamera.camera.fieldOfView = 60;
    175.             }
    176.             weaponCamera.camera.fieldOfView += 50 * Time.deltaTime/0.2;
    177.             if(weaponCamera.camera.fieldOfView > 50){
    178.                 weaponCamera.camera.fieldOfView = 50;
    179.             }
    180.         }
    181.  
    182.         if(player.rigidbody.velocity.magnitude > 3.0){
    183.             triggerTime += inaccuracyDecreaseOverTime;
    184.         }
    185.  
    186.         if(isFiring){
    187.             triggerTime += inaccuracyIncreaseOverTime;
    188.         }else{
    189.             if(player.rigidbody.velocity.magnitude < 3.0)
    190.             triggerTime -= inaccuracyDecreaseOverTime;
    191.         }
    192.  
    193.         if (triggerTime >= maximumInaccuracy) {
    194.             triggerTime = maximumInaccuracy;
    195.         }
    196.  
    197.         if (triggerTime <= baseInaccuracy) {
    198.             triggerTime = baseInaccuracy;
    199.         }
    200.    
    201.         if(nextFireTime > Time.time){
    202.             isFiring = false;
    203.         }
    204.     }
    205. }
    206.  
    207. function LateUpdate(){
    208.     if (m_LastFrameShot == Time.frameCount && !inScope){
    209.         muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward);
    210.         muzzleFlash.enabled = true;
    211.         muzzleLight.enabled = true;    
    212.     }else{
    213.         muzzleFlash.enabled = false;
    214.         muzzleLight.enabled = false;
    215.     }
    216. }
    217.  
    218. function OnGUI (){
    219.     if(selected){
    220.         GUI.skin = mySkin;
    221.         var style1 = mySkin.customStyles[0];
    222.    
    223.         if(selected){
    224.             GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80),"Bullets : ");
    225.             GUI.Label (Rect(Screen.width - 110,Screen.height-35,200,80),"" + bulletsLeft, style1);
    226.             GUI.Label (Rect(Screen.width - 80,Screen.height-35,200,80)," / " + magazines);
    227.         }
    228.    
    229.         if(scopeTexture != null && inScope){
    230.             GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height), scopeTexture, ScaleMode.StretchToFill);
    231.         }else{
    232.             if(crosshairFirstModeHorizontal != null){
    233.                 var w = crosshairFirstModeHorizontal.width;
    234.                 var h = crosshairFirstModeHorizontal.height;
    235.                 position1 = Rect((Screen.width + w)/2 + (triggerTime * adjustMaxCroshairSize),(Screen.height - h)/2, w, h);
    236.                 position2 = Rect((Screen.width - w)/2,(Screen.height + h)/2 + (triggerTime * adjustMaxCroshairSize), w, h);
    237.                 position3 = Rect((Screen.width - w)/2 - (triggerTime * adjustMaxCroshairSize) - w,(Screen.height - h )/2, w, h);
    238.                 position4 = Rect((Screen.width - w)/2,(Screen.height - h)/2 - (triggerTime * adjustMaxCroshairSize) - h, w, h);
    239.                 if (!aiming) {
    240.                     GUI.DrawTexture(position1, crosshairFirstModeHorizontal);     //Right
    241.                     GUI.DrawTexture(position2, crosshairFirstModeVertical);     //Up
    242.                     GUI.DrawTexture(position3, crosshairFirstModeHorizontal);     //Left
    243.                     GUI.DrawTexture(position4, crosshairFirstModeVertical);        //Down
    244.                 }
    245.             }
    246.         }
    247.     }    
    248. }
    249.  
    250.  
    251. function fireSniper (){
    252.     if (reloading || bulletsLeft <= 0){
    253.         if(bulletsLeft == 0){
    254.             OutOfAmmo();
    255.         }    
    256.        return;
    257.     }
    258.  
    259.     if (Time.time - fireRate > nextFireTime)
    260.         nextFireTime = Time.time - Time.deltaTime;
    261.  
    262.         while(nextFireTime < Time.time){
    263.             fireOneBullet();
    264.             nextFireTime = Time.time + fireRate;
    265.     }
    266. }
    267.  
    268. function fireOneBullet (){
    269.     if (nextFireTime > Time.time || draw){
    270.         if(bulletsLeft <= 0){
    271.             OutOfAmmo();
    272.         }
    273.         return;
    274.     }
    275.  
    276.     var direction = mainCamera.transform.TransformDirection(Vector3(Random.Range(-0.05, 0.05) * triggerTime/3, Random.Range(-0.05, 0.05) * triggerTime/3,1));
    277.     var hit : RaycastHit;
    278.     var position = transform.parent.position;
    279.  
    280.     if (Physics.Raycast (position, direction, hit, range, layerMask.value)) {
    281.  
    282.        var contact = hit.point;
    283.         var rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
    284.    
    285.         if (hit.rigidbody){
    286.             hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
    287.         }
    288.    
    289.         if(hit.transform.tag == "Fracture"){
    290.             hit.transform.GetComponent("SimpleFracture").Fracture(contact,direction, true);
    291.         }
    292.  
    293.         if (hit.transform.tag == "Untagged") {
    294.             var default1 = Network.Instantiate (untagged, contact, rotation, 0);
    295.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    296.             //default1.transform.parent = hit.transform;
    297.             //Network.Instantiate(untagged, contact, rotation, 0);
    298.         }
    299.    
    300.         if (hit.transform.tag == "Concrete") {
    301.             var bulletHole = Network.Instantiate (Concrete, contact, rotation, 0);
    302.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    303.             //bulletHole.transform.parent = hit.transform;
    304.         }
    305.    
    306.         if (hit.transform.tag == "Wood") {
    307.             var woodHole = Network.Instantiate (Wood, contact, rotation, 0);
    308.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    309.             //woodHole.transform.parent = hit.transform;
    310.         }
    311.    
    312.         if (hit.transform.tag == "Metal") {
    313.             var metalHole = Network.Instantiate (Metal, contact, rotation, 0);
    314.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    315.             //metalHole.transform.parent = hit.transform;
    316.         }
    317.    
    318.    
    319.         if (hit.transform.tag == "Dirt") {
    320.             var dirtHole = Network.Instantiate (Dirt, contact, rotation, 0);
    321.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    322.             //dirtHole.transform.parent = hit.transform;
    323.         }
    324.    
    325.         if (hit.transform.tag == "canBeUsed") {
    326.             hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    327.         }
    328.    
    329.         if (hit.transform.tag == "Enemy") {
    330.             hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    331.        
    332.             yield WaitForSeconds(0.02);
    333.             var bloodHole = Instantiate (Blood, contact, rotation) as GameObject;
    334.             if(Physics.Raycast (position, direction, hit, range, layerMask.value)){
    335.                 if(hit.rigidbody){
    336.                     hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
    337.                 }
    338.             }
    339.         }
    340.     }
    341.  
    342.     PlayAudioClip(soundFire, transform.position, 0.7);
    343.     m_LastFrameShot = Time.frameCount;
    344.  
    345.     weaponAnim.animation.Rewind("sniperFire");
    346.     weaponAnim.animation.Play("sniperFire");
    347.     bulletsLeft--;
    348.     KickBack();
    349. }
    350.  
    351. function OutOfAmmo(){
    352.     if(reloading || playing)
    353.     return;
    354.  
    355.     playing = true;
    356.     yield WaitForSeconds(0.2);
    357.     PlayAudioClip(soundEmpty, transform.position, 0.7);
    358.     yield WaitForSeconds(0.2);
    359.     playing = false;
    360. }
    361.  
    362. function PlayAudioClip (clip : AudioClip, position : Vector3, volume : float) {
    363.     var go = new GameObject ("One shot audio");
    364.     go.transform.position = position;
    365.     var source : AudioSource = go.AddComponent (AudioSource);
    366.     source.clip = clip;
    367.     source.volume = volume;
    368.     source.pitch = Random.Range(0.95,1.05);
    369.     source.Play ();
    370.     Destroy (go, clip.length);
    371.     return source;
    372. }
    373.  
    374. function Reload (){
    375.     if(reloading)
    376.     return;
    377.  
    378.     reloading = true;
    379.     if (magazines > 0 && bulletsLeft < bulletsPerMag) {
    380.         weaponAnim.animation["Reload"].speed = 1.0;
    381.         weaponAnim.animation.Play("Reload", PlayMode.StopAll);
    382.        weaponAnim.animation.CrossFade("Reload");
    383.         audio.PlayOneShot(soundReload);
    384.         yield WaitForSeconds(reloadTime);
    385.         magazines --;
    386.         bulletsLeft = bulletsPerMag;
    387.     }
    388.     reloading = false;
    389. }
    390.  
    391. function DrawWeapon(){
    392.     draw = true;
    393.     audio.clip = soundDraw;
    394.     audio.Play();
    395.     weaponAnim.animation.Play("Draw", PlayMode.StopAll);
    396.     weaponAnim.animation.CrossFade("Draw");
    397.     yield WaitForSeconds(drawTime);
    398.     draw = false;
    399.     reloading = false;
    400.     selected = true;
    401. }
    402.  
    403. function KickBack() {
    404.     kickGO.localRotation = Quaternion.Euler(kickGO.localRotation.eulerAngles - Vector3(kickUpside, Random.Range(-kickSideways, kickSideways), 0));
    405. }
    406.  
    407. function Deselect(){
    408.     selected = false;
    409.     mainCamera.camera.fieldOfView = 60;
    410.     weaponCamera.camera.fieldOfView = 50;
    411.     inScope = false;
    412.     transform.localPosition = hipPosition;
    413.     var go = GetComponentsInChildren(Renderer);
    414.     for( var g : Renderer in go){
    415.         if (g.name != "muzzle_flash")
    416.             g.renderer.enabled = true;
    417.     }
    418. }
     
    Last edited: Aug 7, 2014
  2. Kokumo

    Kokumo

    Joined:
    Jul 23, 2010
    Posts:
    416
    Did you check if without this script, happens the same?... because you may have some game object which attachs scripts to the weapons, when you run the game.
     
  3. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    I did remove it, This script is called WeaponScriptNEW, when I remove it weapon manager cannot find the file and throws and error.

    thats the manager code
    Code (JavaScript):
    1. /**
    2.  
    3. var weaponsInUse : GameObject[];                    // used weapons, among which you can switch.
    4. var weaponsInGame : GameObject[];                    // all weapons, which could be used in game
    5. var worldModels : Rigidbody[];                         // just a prefab which could be instantiated when you drop weapon
    6.  
    7.     var hit : RaycastHit;
    8.     var distance : float = 2.0;
    9.     var layerMaskWeapon : LayerMask;
    10.     var layerMaskAmmo : LayerMask;
    11.    
    12.     var dropPosition : Transform;
    13.    
    14.     var switchWeaponTime : float = 0.5;
    15.     @HideInInspector
    16.     var canSwitch : boolean = true;
    17.     @HideInInspector
    18.     var showWepGui : boolean = false;
    19.     @HideInInspector
    20.     var showAmmoGui : boolean = false;
    21.     private var equipped : boolean = false;
    22.     //@HideInInspector
    23.     //var i : int = 0;
    24.     //@HideInInspector
    25.     var weaponToSelect : int;
    26.     //@HideInInspector
    27.     var setElement : int;
    28.     //@HideInInspector
    29.     var weaponToDrop : int;
    30.     var mySkin : GUISkin;
    31.     var pickupSound : AudioClip;
    32.     private var textFromPickupScript : String = "";
    33.     private var notes : String = "";
    34.     private var note : String = "Press key <E> to pick up Ammo";
    35.     private var note2 : String = "Select appropriate weapon to pick up ammo";
    36.    
    37.     var playerSpawner : NetworkPlayerSpawner;
    38.  
    39. function Start (){
    40.     playerSpawner = gameObject.Find("_MultiplayerManager").GetComponent("NetworkPlayerSpawner");
    41.     weaponsInUse[0] = weaponsInGame[playerSpawner.createdClass[0]];
    42.     weaponsInUse[1] = weaponsInGame[playerSpawner.createdClass[1]];
    43.     for (var h : int = 0; h < worldModels.length; h++){
    44.         weaponsInGame[h].gameObject.SetActive(false);
    45.     }  
    46.     weaponToSelect = 0;
    47.     DeselectWeapon();
    48. }
    49.  
    50.  
    51. function Update () {
    52.  
    53.     if (Input.GetKeyDown("1") && weaponsInUse.length >= 1 && canSwitch && weaponToSelect != 0) {
    54.         DeselectWeapon();
    55.         weaponToSelect = 0;
    56.  
    57.     } else if (Input.GetKeyDown("2") && weaponsInUse.length >= 2 && canSwitch && weaponToSelect != 1) {
    58.         DeselectWeapon();
    59.         weaponToSelect = 1;
    60.  
    61.     }
    62.    
    63.     if (Input.GetAxis("Mouse ScrollWheel") > 0 && canSwitch){
    64.             weaponToSelect++;
    65.         if (weaponToSelect > (weaponsInUse.length - 1)){
    66.             weaponToSelect = 0;
    67.         }
    68.         DeselectWeapon();
    69.     }
    70.    
    71.     if (Input.GetAxis("Mouse ScrollWheel") < 0 && canSwitch){
    72.         weaponToSelect--;
    73.         if (weaponToSelect < 0){
    74.             weaponToSelect = weaponsInUse.length - 1;
    75.         }
    76.         DeselectWeapon();
    77.     }
    78.    
    79.     var position = transform.parent.position;
    80.     var direction : Vector3 = transform.TransformDirection (Vector3.forward);
    81.     if (Physics.Raycast (position, direction, hit, distance, layerMaskWeapon.value)){
    82.  
    83.         var prefab : WeaponIndex = hit.transform.GetComponent("WeaponIndex");
    84.         setElement = prefab.setWeapon;
    85.         showWepGui = true;
    86.                                                                                                             //if you want more than 2 weapons equip at the same time      
    87.         if(weaponsInUse[0] != weaponsInGame[setElement] && weaponsInUse[1] != weaponsInGame[setElement]){ //&& weaponsInUse[2] != weaponsInGame[setElement] && weaponsInUse[3] != weaponsInGame[setElement]){
    88.             equipped = false;
    89.         }else{
    90.             equipped = true;
    91.         }
    92.        
    93.         if(canSwitch){
    94.             if(!equipped && Input.GetKeyDown ("e")){
    95.                 DropWeapon(weaponToDrop);
    96.                 DeselectWeapon();
    97.                 weaponsInUse[weaponToSelect] = weaponsInGame[setElement];
    98.                     if(setElement == 8){
    99.                         var pickupGOW1 : Pickup = hit.transform.GetComponent("Pickup");
    100.                         addStickGrenades(pickupGOW1.amount);
    101.                     }  
    102.                 Destroy(hit.collider.transform.parent.gameObject);
    103.                
    104.             }else{  
    105.            
    106.                 if(setElement == 8){
    107.                     if(Input.GetKeyDown ("e")){
    108.                         var pickupGOW : Pickup = hit.transform.GetComponent("Pickup");
    109.                         addStickGrenades(pickupGOW.amount);
    110.                         Destroy(hit.collider.transform.parent.gameObject);
    111.                     }
    112.                 }
    113.             }          
    114.         }
    115.    
    116.     }else{
    117.         showWepGui = false;
    118.     }
    119.    
    120.     if (Physics.Raycast (position, direction, hit, distance, layerMaskAmmo.value)){
    121.         showAmmoGui = true;
    122.         if(hit.transform.CompareTag("Ammo")){
    123.             var pickupGO : Pickup = hit.transform.GetComponent("Pickup");
    124.            
    125.             //ammo for pistols, rifles
    126.             if (pickupGO.pickupType == PickupType.Magazines) {
    127.                 var mags : WeaponScriptNEW = weaponsInUse[weaponToSelect].gameObject.transform.GetComponent("WeaponScriptNEW");
    128.                 if(mags != null && mags.firstMode != fireMode.launcher){
    129.                     notes = "";
    130.                     textFromPickupScript = note;
    131.                     if(Input.GetKeyDown ("e")){
    132.                         if(mags.ammoMode == Ammo.Magazines){
    133.                             mags.magazines += pickupGO.amount;
    134.                         }else{
    135.                             mags.magazines += pickupGO.amount * mags.bulletsPerMag;
    136.                         }  
    137.                         audio.clip = pickupSound;
    138.                         audio.Play();  
    139.                         Destroy(hit.collider.gameObject);
    140.                     }  
    141.                 }else{
    142.                     textFromPickupScript = pickupGO.AmmoInfo;
    143.                     notes = note2;
    144.                 }
    145.             }
    146.             //ammo for Sniper rifle
    147.             if (pickupGO.pickupType == PickupType.SniperMagazines) {
    148.                 var magsSniper : SniperScript = weaponsInUse[weaponToSelect].gameObject.transform.GetComponent("SniperScript");
    149.                 if(magsSniper != null){
    150.                     notes = "";
    151.                     textFromPickupScript = note;
    152.                     if(Input.GetKeyDown ("e")){
    153.                         magsSniper.magazines += pickupGO.amount;
    154.                         audio.clip = pickupSound;
    155.                         audio.Play();  
    156.                         Destroy(hit.collider.gameObject);
    157.                     }  
    158.                 }else{
    159.                     textFromPickupScript = pickupGO.AmmoInfo;
    160.                     notes = note2;
    161.                 }  
    162.             }
    163.             //ammo for weapon if second fireMode is luancher
    164.             if (pickupGO.pickupType == PickupType.Projectiles) {
    165.                 var projectile : WeaponScriptNEW = weaponsInUse[weaponToSelect].gameObject.transform.GetComponent("WeaponScriptNEW");
    166.                 if(projectile != null && projectile.secondMode == fireMode.launcher){
    167.                     notes = "";
    168.                     textFromPickupScript = note;
    169.                     if(Input.GetKeyDown ("e")){
    170.                         projectile.projectiles += pickupGO.amount;
    171.                         audio.clip = pickupSound;
    172.                         audio.Play();  
    173.                         Destroy(hit.collider.gameObject);
    174.                     }  
    175.                 }else{
    176.                     textFromPickupScript = pickupGO.AmmoInfo;
    177.                     notes = note2;
    178.                 }
    179.             }
    180.             //ammo for rocket launcher
    181.             if (pickupGO.pickupType == PickupType.Rockets) {
    182.                 var rockets : WeaponScriptNEW = weaponsInUse[weaponToSelect].gameObject.transform.GetComponent("WeaponScriptNEW");
    183.                 if(rockets != null && rockets.firstMode == fireMode.launcher){
    184.                     notes = "";
    185.                     textFromPickupScript = note;
    186.                     if(Input.GetKeyDown ("e")){
    187.                         rockets.projectiles += pickupGO.amount;
    188.                         rockets.EnableProjectileRenderer();
    189.                         audio.clip = pickupSound;
    190.                         audio.Play();  
    191.                         Destroy(hit.collider.gameObject);  
    192.                     }  
    193.                 }else{
    194.                     textFromPickupScript = pickupGO.AmmoInfo;
    195.                     notes = note2;
    196.                 }  
    197.             }
    198.             //ammo for shotgun
    199.             if (pickupGO.pickupType == PickupType.Shells) {
    200.                 var bullets : ShotGunScriptNEW = weaponsInUse[weaponToSelect].gameObject.transform.GetComponent("ShotGunScriptNEW");
    201.                 if(bullets != null){
    202.                     notes = "";
    203.                     textFromPickupScript = note;
    204.                    
    205.                     if(Input.GetKeyDown ("e")){
    206.                         bullets.magazines += pickupGO.amount;
    207.                         audio.clip = pickupSound;
    208.                         audio.Play();  
    209.                         Destroy(hit.collider.gameObject);
    210.                     }
    211.                 }else{
    212.                     textFromPickupScript = pickupGO.AmmoInfo;
    213.                     notes = note2;
    214.                 }
    215.             }
    216.             //pickup health
    217.             if (pickupGO.pickupType == PickupType.Health) {
    218.                 textFromPickupScript = pickupGO.AmmoInfo;
    219.                 notes = "";
    220.                 if(Input.GetKeyDown ("e")){
    221.                     var playerGO = GameObject.Find("Player");
    222.                     var hp : PlayerDamageNew = playerGO.gameObject.transform.GetComponent("PlayerDamageNew");
    223.                     hp.hitPoints += pickupGO.amount;
    224.                     audio.clip = pickupSound;
    225.                     audio.Play();    
    226.                     Destroy(hit.collider.gameObject);
    227.                 }
    228.             }
    229.         }  
    230.    
    231.     }else{
    232.         showAmmoGui = false;
    233.     }  
    234. }
    235.  
    236. function addStickGrenades(amount : int){
    237.     yield WaitForSeconds(.5);
    238.     var stickGrenade : GrenadeScript = weaponsInGame[8].gameObject.transform.GetComponent("GrenadeScript");
    239.     stickGrenade.grenadeCount += amount;
    240.     stickGrenade.DrawWeapon();
    241. }
    242.  
    243. function OnGUI(){
    244.     GUI.skin = mySkin;
    245.     var style1 = mySkin.customStyles[0];
    246.     if(showWepGui){
    247.         if(!equipped){
    248.             GUI.Label(Rect(Screen.width - (Screen.width/1.7),Screen.height - (Screen.height/1.4),800,100),"Press key << E >> to pickup weapon", style1);
    249.         }else{  
    250.             GUI.Label(Rect(Screen.width - (Screen.width/1.7),Screen.height - (Screen.height/1.4),800,100),"Weapon is already equipped");
    251.         }
    252.     }
    253.  
    254.     if(showAmmoGui){
    255.         GUI.Label(Rect(Screen.width - (Screen.width/1.7),Screen.height - (Screen.height/1.4),800,200), notes + "\n" + textFromPickupScript, style1);
    256.     }  
    257. }
    258.  
    259. function DeselectWeapon(){
    260.     //Dectivate all weapon
    261.     for (var i : int = 0; i < weaponsInUse.length; i++){
    262.         weaponsInUse[i].gameObject.SendMessage("Deselect", SendMessageOptions.DontRequireReceiver);
    263.         var deactivate : Component[] = weaponsInUse[i].gameObject.GetComponentsInChildren(MonoBehaviour);
    264.         for (var d in deactivate) {
    265.             var d : MonoBehaviour = d as MonoBehaviour;
    266.             if (d)
    267.             d.enabled = false;
    268.         }
    269.         weaponsInUse[i].gameObject.SetActive(false);
    270.     }
    271.     Wait();
    272. }
    273.  
    274. function Wait(){
    275.     canSwitch = false;
    276.     yield WaitForSeconds(switchWeaponTime);
    277.     SelectWeapon(weaponToSelect);
    278.     yield WaitForSeconds(switchWeaponTime);
    279.     canSwitch = true;
    280. }
    281.  
    282. function SelectWeapon (i : int) {
    283.     //Activate selected weapon
    284.     weaponsInUse[i].gameObject.SetActive(true);
    285.     var activate : Component[] = weaponsInUse[i].gameObject.GetComponentsInChildren(MonoBehaviour);
    286.     for (var a in activate) {
    287.         var a : MonoBehaviour = a as MonoBehaviour;
    288.         if (a)
    289.         a.enabled = true;
    290.     }
    291.     weaponsInUse[i].gameObject.SendMessage("DrawWeapon", SendMessageOptions.DontRequireReceiver);
    292.     var temp : WeaponIndex = weaponsInUse[i].gameObject.transform.GetComponent("WeaponIndex");
    293.     weaponToDrop = temp.setWeapon;
    294. }
    295.  
    296. function DropWeapon(index : int){
    297.    
    298.     for (var i : int = 0; i < worldModels.length; i++){
    299.         if (i == index){
    300.             var drop : Rigidbody = Instantiate(worldModels[i], dropPosition.transform.position, dropPosition.transform.rotation);
    301.             drop.AddRelativeForce(0,50,Random.Range(100, 200));
    302.         }
    303.     }  
    304. }
    305.  
    306.  
    307.    
    308.  
     
  4. Zenov

    Zenov

    Joined:
    Jul 28, 2014
    Posts:
    53
    I looked over the code and don't see where it could be happening.

    Going to sound strange but try restarting Unity (I recently had objects appearing out of no where. Turned out that it was Unity acting up)
     
  5. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    I have many times.. :/
     
  6. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    There are no scripts on the guns, other then weapon index,
     
  7. Kokumo

    Kokumo

    Joined:
    Jul 23, 2010
    Posts:
    416
    As far as I can see, there is nothing noticeable that could make, the beahaviour you described it, happens.

    The only thing that could make your weapons to have values, are these lines in WeaponScriptNEW.
    Code (JavaScript):
    1. var damage : int = 50;
    2. var bulletsPerMag : int = 50;
    3. var magazines : int = 5;
    4. var reloadTime = 2;
     
  8. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    I've even take thoes lines and made a new .js files and set them to the weapon, the values wont change.. even If I changed them in the file.
     
  9. Kokumo

    Kokumo

    Joined:
    Jul 23, 2010
    Posts:
    416
    WeaponIndex has any hardcoded value?
    Do you have any prefab?
     
  10. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
  11. Kokumo

    Kokumo

    Joined:
    Jul 23, 2010
    Posts:
    416
    "Weapon test ammo" sounds new for me... different from "WeaponScriptNEW": what is it for?
    The info that appears in the inspector, belongs to the weapon that the character is holding on his hands?
     
  12. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    Yes, if you see in the inspector, I set the clips to 2 for that gun but in game its still 5.. and Weapon Test ammo was a 2 second script that holds:

    Code (JavaScript):
    1. var damage : int = 50;
    2. var bulletsPerMag : int = 50;
    3. var magazines : int = 5;
    4. var reloadTime = 2;
    and still doesent change it.. (the scripts are appied to the prefabs..
     
  13. Kokumo

    Kokumo

    Joined:
    Jul 23, 2010
    Posts:
    416
    This is very strange; I have no clue about it.
    I believe you have an object in the scene that initialize the weapons's values; in other way, that's impossible.
    Maybe you have a prefab with nested models with a script attached, and we are not thinking about it.

    It is time to comment code xD!
    Left WeaponScriptNEW in place, and comment everything... then, press play (some issue will pops up, so you will need to uncomment a couple of methds). If the weapon shows expected values, keep on uncommenting codes until you realize some changes. At that point, you will need to follow references until find th problem... or wait for another response =/
     
  14. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    Give me 5-10 mins before I reply again I'll try and see what happens..
    if it helps at all, this is multiplayer
     
  15. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    I removed all but the weapon values (This is what I removed) Some weapons still work some dont.

    Code (JavaScript):
    1. function Start(){
    2.     weaponCamera = GameObject.FindWithTag("WeaponCamera");
    3.     mainCamera = GameObject.FindWithTag("MainCamera");
    4.     player = GameObject.FindWithTag("Player");
    5.     muzzleFlash.enabled = false;
    6.     muzzleLight.enabled = false;
    7.     bulletsLeft = bulletsPerMag;
    8.     currentMode = firstMode;
    9.     fireRate = fireRateFirstMode;
    10.     aiming = false;
    11.     if(firstMode == fireMode.launcher){
    12.         rocket = GameObject.Find("RPGrocket");
    13.     }
    14.     if(ammoMode == Ammo.Bullets){
    15.         magazines = magazines * bulletsPerMag;
    16.     }
    17. }  
    18.    
    19. function Update(){
    20.     if(selected){
    21.        
    22.         if(Screen.lockCursor){
    23.             if (Input.GetButtonDown ("Fire")){
    24.                 if(currentMode == fireMode.semi){
    25.                     fireSemi();
    26.                 }
    27.            
    28.                 if(currentMode == fireMode.launcher){
    29.                     fireLauncher();
    30.                 }
    31.                
    32.                 if(currentMode == fireMode.burst){
    33.                     fireBurst();
    34.                 }
    35.                
    36.                 if(bulletsLeft > 0)
    37.                 isFiring = true;  
    38.             }
    39.            
    40.             if (Input.GetButton ("Fire")){
    41.                 if(currentMode == fireMode.auto){
    42.                     fireSemi();
    43.                     if(bulletsLeft > 0)
    44.                     isFiring = true;
    45.                 }  
    46.             }
    47.            
    48.             if (Input.GetButtonDown ("Reload")){
    49.                 Reload();
    50.             }
    51.         }
    52.     }
    53.  
    54.     if (Input.GetButton("Fire2") && !Input.GetButton ("Run") && !reloading){      
    55.         if (!aiming){
    56.             aiming = true;
    57.             curVect = aimPosition - transform.localPosition;
    58.         }
    59.         if (transform.localPosition != aimPosition && aiming){
    60.             if(Mathf.Abs(Vector3.Distance(transform.localPosition , aimPosition)) < curVect.magnitude/aimSpeed * Time.deltaTime){
    61.                 transform.localPosition = aimPosition;
    62.             } else {
    63.                 transform.localPosition += curVect/aimSpeed * Time.deltaTime;                  
    64.             }
    65.         }
    66.     } else {
    67.         if (aiming){
    68.             aiming = false;
    69.             curVect = hipPosition - transform.localPosition;
    70.             /*
    71.             var go = GetComponentsInChildren(Renderer);
    72.             for( var g : Renderer in go){
    73.             if (g.name != "muzzle_flash")
    74.                 g.renderer.enabled = true;
    75.             }
    76.             */
    77.         }
    78.        
    79.         if(Mathf.Abs(Vector3.Distance(transform.localPosition , hipPosition)) < curVect.magnitude/aimSpeed * Time.deltaTime){
    80.             transform.localPosition = hipPosition;
    81.         }else{
    82.             transform.localPosition += curVect/aimSpeed * Time.deltaTime;
    83.         }
    84.     }
    85.        
    86.     if(aiming){
    87.         maximumInaccuracy = maxInaccuracyAIM;
    88.         baseInaccuracy = baseInaccuracyAIM;
    89.         mainCamera.camera.fieldOfView -= FOV * Time.deltaTime/zoomSpeed;
    90.         if(mainCamera.camera.fieldOfView < FOV){
    91.             mainCamera.camera.fieldOfView = FOV;
    92.         }
    93.         weaponCamera.camera.fieldOfView -= 40 * Time.deltaTime/zoomSpeed;
    94.         if(weaponCamera.camera.fieldOfView < 40){
    95.             weaponCamera.camera.fieldOfView = 40;
    96.         }
    97.     }else{
    98.         maximumInaccuracy = maxInaccuracyHIP;
    99.         baseInaccuracy = baseInaccuracyHIP;
    100.         mainCamera.camera.fieldOfView += 60 * Time.deltaTime/0.5;
    101.         if(mainCamera.camera.fieldOfView > 60){
    102.             mainCamera.camera.fieldOfView = 60;
    103.         }
    104.         weaponCamera.camera.fieldOfView += 50 * Time.deltaTime/0.5;
    105.         if(weaponCamera.camera.fieldOfView > 50){
    106.             weaponCamera.camera.fieldOfView = 50;
    107.         }
    108.     }
    109.    
    110.     if(player.rigidbody.velocity.magnitude > 3.0){
    111.         triggerTime += inaccuracyDecreaseOverTime;
    112.     }
    113.  
    114.     if(isFiring){
    115.         triggerTime += inaccuracyIncreaseOverTime;
    116.     }else{
    117.         if(player.rigidbody.velocity.magnitude < 3.0)
    118.         triggerTime -= inaccuracyDecreaseOverTime;
    119.     }
    120.    
    121.     if (triggerTime >= maximumInaccuracy) {
    122.         triggerTime = maximumInaccuracy;
    123.     }
    124.    
    125.     if (triggerTime <= baseInaccuracy) {
    126.         triggerTime = baseInaccuracy;
    127.     }
    128.  
    129.     if(nextFireTime > Time.time){
    130.         isFiring = false;
    131.     }  
    132.    
    133.     if(Input.GetButtonDown("switchFireMode") && secondMode != fireMode.none && canSwicthMode){
    134.         if(currentMode != firstMode){
    135.             FirstFireMode();
    136.         }else{
    137.             SecondFireMode();
    138.         }
    139.     }          
    140. }
    141.  
    142.  
    143. function LateUpdate(){
    144.     if (m_LastFrameShot == Time.frameCount){
    145.         muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward);
    146.         muzzleFlash.enabled = true;
    147.         muzzleLight.enabled = true;      
    148.     }else{
    149.         muzzleFlash.enabled = false;
    150.         muzzleLight.enabled = false;
    151.     }  
    152. }
    153.  
    154. function OnGUI (){
    155.     if(selected){
    156.         GUI.skin = mySkin;
    157.         var style1 = mySkin.customStyles[0];
    158.         if(ammoMode == Ammo.Magazines){
    159.             if(firstMode != fireMode.none && firstMode != fireMode.launcher || secondMode != fireMode.none && secondMode != fireMode.launcher){
    160.                 GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80),"Ammo : ");
    161.                 GUI.Label (Rect(Screen.width - 110,Screen.height-35,200,80),"" + bulletsLeft, style1);
    162.                 GUI.Label (Rect(Screen.width - 80,Screen.height-35,200,80)," / " + magazines);
    163.             }
    164.         }  
    165.        
    166.         if(ammoMode == Ammo.Bullets){
    167.             if(firstMode != fireMode.none && firstMode != fireMode.launcher || secondMode != fireMode.none && secondMode != fireMode.launcher){
    168.                 GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80),"Bullets : ");
    169.                 GUI.Label (Rect(Screen.width - 110,Screen.height-35,200,80),"" + bulletsLeft, style1);
    170.                 GUI.Label (Rect(Screen.width - 80,Screen.height-35,200,80)," |  " + magazines);
    171.             }  
    172.         }
    173.        
    174.         if(firstMode != fireMode.none || secondMode != fireMode.none){
    175.             GUI.Label (Rect(Screen.width - 200,Screen.height-65,200,80),"Firing Mode :");
    176.             GUI.Label (Rect(Screen.width - 110,Screen.height-65,200,80),"" + currentMode, style1);
    177.         }
    178.        
    179.         if(secondMode == fireMode.launcher || firstMode == fireMode.launcher){
    180.             GUI.Label (Rect(Screen.width - 200,Screen.height-95,200,80),"Projectiles : ");
    181.             GUI.Label (Rect(Screen.width - 110,Screen.height-95,200,80),"" + projectiles, style1);
    182.         }  
    183.        
    184.         if(crosshairFirstModeHorizontal != null){  
    185.             if(currentMode != fireMode.launcher){
    186.                 var w = crosshairFirstModeHorizontal.width;
    187.                 var h = crosshairFirstModeHorizontal.height;
    188.                 position1 = Rect((Screen.width + w)/2 + (triggerTime * adjustMaxCroshairSize),(Screen.height - h)/2, w, h);
    189.                 position2 = Rect((Screen.width - w)/2,(Screen.height + h)/2 + (triggerTime * adjustMaxCroshairSize), w, h);
    190.                 position3 = Rect((Screen.width - w)/2 - (triggerTime * adjustMaxCroshairSize) - w,(Screen.height - h )/2, w, h);
    191.                 position4 = Rect((Screen.width - w)/2,(Screen.height - h)/2 - (triggerTime * adjustMaxCroshairSize) - h, w, h);
    192.                 if (!aiming) {
    193.                     GUI.DrawTexture(position1, crosshairFirstModeHorizontal);     //Right
    194.                     GUI.DrawTexture(position2, crosshairFirstModeVertical);     //Up
    195.                     GUI.DrawTexture(position3, crosshairFirstModeHorizontal);     //Left
    196.                     GUI.DrawTexture(position4, crosshairFirstModeVertical);        //Down
    197.                 }
    198.             }
    199.         }  
    200.        
    201.         if(crosshairSecondMode != null){
    202.             if(currentMode == fireMode.launcher){
    203.                 var width = crosshairSecondMode.width/2;
    204.                 var height = crosshairSecondMode.height/2;
    205.                 position = Rect((Screen.width - width)/2,(Screen.height - height )/2, width, height);
    206.                 if (!aiming) {
    207.                     GUI.DrawTexture(position, crosshairSecondMode);
    208.                 }
    209.             }
    210.         }  
    211.     }  
    212. }
    213.  
    214. function FirstFireMode(){
    215.    
    216.     canSwicthMode = false;
    217.     selected = false;
    218.     weaponAnim.animation.Rewind("SwitchAnim");
    219.     weaponAnim.animation.Play("SwitchAnim");
    220.     audio.clip = switchModeSound;
    221.     audio.Play();
    222.     yield WaitForSeconds(0.6);
    223.     currentMode = firstMode;
    224.     fireRate = fireRateFirstMode;
    225.     selected = true;
    226.     canSwicthMode = true;
    227. }
    228.  
    229. function SecondFireMode(){
    230.    
    231.     canSwicthMode = false;
    232.     selected = false;
    233.     audio.clip = switchModeSound;
    234.     audio.Play();
    235.     weaponAnim.animation.Play("SwitchAnim");
    236.     yield WaitForSeconds(0.6);
    237.     currentMode = secondMode;
    238.     fireRate = fireRateSecondMode;
    239.     selected = true;
    240.     canSwicthMode = true;
    241.    
    242. }
    243.  
    244. function fireSemi (){
    245.     if (reloading || bulletsLeft <= 0){
    246.         if(bulletsLeft == 0){
    247.             OutOfAmmo();
    248.         }      
    249.         return;
    250.     }
    251.    
    252.     if (Time.time - fireRate > nextFireTime)
    253.         nextFireTime = Time.time - Time.deltaTime;
    254.  
    255.         while(nextFireTime < Time.time){
    256.             fireOneBullet();
    257.             nextFireTime = Time.time + fireRate;
    258.     }
    259. }
    260.  
    261. function fireLauncher (){
    262.     if (reloading || projectiles <= 0){
    263.         if(projectiles == 0){
    264.             OutOfAmmo();
    265.         }      
    266.         return;
    267.     }
    268.    
    269.     if (Time.time - fireRate > nextFireTime)
    270.         nextFireTime = Time.time - Time.deltaTime;
    271.  
    272.         while(nextFireTime < Time.time){
    273.             fireProjectile();
    274.             nextFireTime = Time.time + fireRate;
    275.     }
    276. }
    277.  
    278. function fireBurst (){
    279.     var shotCounter : int = 0;
    280.    
    281.     if (reloading || bursting || bulletsLeft <= 0){
    282.         if(bulletsLeft <= 0){
    283.             OutOfAmmo();
    284.         }      
    285.         return;
    286.     }
    287.    
    288.     if (Time.time - fireRate > nextFireTime)
    289.         nextFireTime = Time.time - Time.deltaTime;
    290.  
    291.     if(Time.time > nextFireTime){
    292.         while (shotCounter < shotsPerBurst){
    293.             bursting = true;
    294.             shotCounter++;
    295.             if (bulletsLeft > 0){
    296.                 fireOneBullet();
    297.             }          
    298.             yield WaitForSeconds(burstTime);
    299.         }          
    300.         nextFireTime = Time.time + fireRate;
    301.     }
    302.     bursting = false;
    303. }
    304.  
    305.  
    306. function fireOneBullet (){
    307.     if (nextFireTime > Time.time || draw){
    308.         if(bulletsLeft <= 0){
    309.             OutOfAmmo();
    310.         }  
    311.         return;
    312.     }
    313.    
    314.     var direction = gameObject.transform.TransformDirection(Vector3(Random.Range(-0.01, 0.01) * triggerTime, Random.Range(-0.01, 0.01) * triggerTime,1));
    315.     var hit : RaycastHit;
    316.     var position = transform.parent.position;
    317.  
    318.     if (Physics.Raycast(position, direction, hit, range, layerMask.value)) {
    319.    
    320.         var contact = hit.point;
    321.         var rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
    322.        
    323.         if (hit.rigidbody){
    324.             hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
    325.         }
    326.  
    327.         if (hit.transform.tag == "Untagged") {
    328.             var default1 = Network.Instantiate (untagged, contact, rotation, 0);
    329.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    330.             //default1.transform.parent = hit.transform;
    331.             //Network.Instantiate(untagged, contact, rotation, 0);
    332.         }
    333.        
    334.         if (hit.transform.tag == "Concrete") {
    335.             var bulletHole = Network.Instantiate (Concrete, contact, rotation, 0);
    336.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    337.             //bulletHole.transform.parent = hit.transform;
    338.         }  
    339.        
    340.         if (hit.transform.tag == "Wood") {
    341.             var woodHole = Network.Instantiate (Wood, contact, rotation, 0);
    342.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    343.             //woodHole.transform.parent = hit.transform;
    344.         }
    345.        
    346.         if (hit.transform.tag == "Metal") {
    347.             var metalHole = Network.Instantiate (Metal, contact, rotation, 0);
    348.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    349.             //metalHole.transform.parent = hit.transform;
    350.         }
    351.        
    352.        
    353.         if (hit.transform.tag == "Dirt") {
    354.             var dirtHole = Network.Instantiate (Dirt, contact, rotation, 0);
    355.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    356.             //dirtHole.transform.parent = hit.transform;
    357.         }
    358.        
    359.         if (hit.transform.tag == "canBeUsed") {
    360.             hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    361.         }  
    362.        
    363.         if (hit.transform.tag == "Enemy") {
    364.             hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    365.            
    366.             yield WaitForSeconds(0.01);
    367.             var bloodHole = Instantiate (Blood, contact, rotation) as GameObject;
    368.             if(Physics.Raycast (position, direction, hit, range, layerMask.value)){
    369.                 if(hit.rigidbody){
    370.                     hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
    371.                 }
    372.             }  
    373.         }
    374.     }
    375.    
    376.     PlayAudioClip(soundFire, transform.position, 0.7);
    377.     m_LastFrameShot = Time.frameCount;
    378.  
    379.     weaponAnim.animation.Rewind("Fire");
    380.     weaponAnim.animation.Play("Fire");
    381.     KickBack();
    382.     bulletsLeft--;
    383. }
    384.  
    385. function PlayAudioClip (clip : AudioClip, position : Vector3, volume : float) {
    386.     var go = new GameObject ("One shot audio");
    387.     go.transform.position = position;
    388.     var source : AudioSource = go.AddComponent (AudioSource);
    389.     source.clip = clip;
    390.     source.volume = volume;
    391.     source.pitch = Random.Range(0.95,1.05);
    392.     source.Play ();
    393.     Destroy (go, clip.length);
    394.     return source;
    395. }
    396.  
    397. function fireProjectile (){
    398.     if (projectiles < 1 || draw || launcjerReload){  
    399.         return;
    400.     }
    401.    
    402.     var instantiatedProjectile : Rigidbody = Network.Instantiate (projectilePrefab, launchPosition.transform.position, launchPosition.transform.rotation, 0);
    403.     fireLauncherAnimGO.animation.Play("FireGL");
    404.     instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, projectileSpeed));
    405.     Physics.IgnoreCollision(instantiatedProjectile.collider, gameObject.FindWithTag("Player").transform.root.collider);
    406.     projectiles--;
    407.    
    408.     if(canReloadLauncher)
    409.     ReloadLauncher();
    410. }
    411.  
    412. function OutOfAmmo(){
    413.     if(reloading || playing)
    414.     return;
    415.    
    416.     playing = true;
    417.     PlayAudioClip(soundEmpty, transform.position, 0.7);
    418.    
    419.     weaponAnim.animation["Fire"].speed = 2.0;
    420.     weaponAnim.animation.Rewind("Fire");
    421.     weaponAnim.animation.Play("Fire");
    422.     yield WaitForSeconds(0.2);
    423.     playing = false;
    424. }
    425. //For RPG
    426. function ReloadLauncher(){
    427.     if(projectiles > 0){
    428.         launcjerReload = true;
    429.         canSwicthMode = false;
    430.         DisableProjectileRenderer();      
    431.         yield WaitForSeconds(0.5);
    432.         audio.PlayOneShot(soundReloadLauncher);
    433.         weaponAnim.animation[reloadlauncher].speed = 1.2;
    434.         weaponAnim.animation.Play(reloadlauncher);
    435.         yield WaitForSeconds(launcherReloadTime);  
    436.         canSwicthMode = true;
    437.         launcjerReload = false;
    438.     }else{
    439.         if(rocket != null && projectiles == 0){
    440.             rocket.renderer.enabled = false;
    441.         }
    442.     }  
    443.    
    444. }
    445.  
    446. function DisableProjectileRenderer(){
    447.     if(rocket != null){
    448.         rocket.renderer.enabled = false;
    449.     }
    450.     yield WaitForSeconds(launcherReloadTime/1.5);
    451.     if(rocket != null){
    452.         rocket.renderer.enabled = true;
    453.     }
    454. }
    455.  
    456. function EnableProjectileRenderer(){
    457.     if(rocket != null){
    458.         rocket.renderer.enabled = true;
    459.     }
    460. }
    461.  
    462. function Reload (){
    463.     if(reloading)
    464.     return;
    465.    
    466.     if(ammoMode == Ammo.Magazines){
    467.         reloading = true;
    468.         canSwicthMode = false;
    469.         if (magazines > 0 && bulletsLeft != bulletsPerMag) {
    470.             weaponAnim.animation["Reload"].speed = reloadAnimSpeed;
    471.             weaponAnim.animation.Play("Reload", PlayMode.StopAll);
    472.             weaponAnim.animation.CrossFade("Reload");
    473.             audio.PlayOneShot(soundReload);
    474.             yield WaitForSeconds(reloadTime);
    475.             magazines --;
    476.             bulletsLeft = bulletsPerMag;
    477.         }
    478.         reloading = false;
    479.         canSwicthMode = true;
    480.         isFiring = false;
    481.     }  
    482.    
    483.     if(ammoMode == Ammo.Bullets){
    484.         if(magazines > 0 && bulletsLeft != bulletsPerMag){
    485.             if(magazines > bulletsPerMag){
    486.                 canSwicthMode = false;
    487.                 reloading = true;
    488.                 weaponAnim.animation["Reload"].speed = reloadAnimSpeed;
    489.                 weaponAnim.animation.Play("Reload", PlayMode.StopAll);
    490.                 weaponAnim.animation.CrossFade("Reload");
    491.                 audio.PlayOneShot(soundReload);
    492.                 yield WaitForSeconds(reloadTime);
    493.                 magazines -= bulletsPerMag - bulletsLeft;
    494.                 bulletsLeft = bulletsPerMag;
    495.                 canSwicthMode = true;
    496.                 reloading = false;
    497.                 return;
    498.             }else{
    499.                 canSwicthMode = false;
    500.                 reloading = true;
    501.                 weaponAnim.animation["Reload"].speed = reloadAnimSpeed;
    502.                 weaponAnim.animation.Play("Reload", PlayMode.StopAll);
    503.                 weaponAnim.animation.CrossFade("Reload");
    504.                 audio.PlayOneShot(soundReload);
    505.                 yield WaitForSeconds(reloadTime);
    506.                 var bullet = Mathf.Clamp(bulletsPerMag, magazines, bulletsLeft + magazines);
    507.                 magazines -= (bullet - bulletsLeft);
    508.                 bulletsLeft = bullet;
    509.                 canSwicthMode = true;
    510.                 reloading = false;
    511.                 return;
    512.             }  
    513.         }  
    514.     }
    515. }
    516.  
    517. function KickBack() {
    518.     kickGO.localRotation = Quaternion.Euler(kickGO.localRotation.eulerAngles - Vector3(kickUpside, Random.Range(-kickSideways, kickSideways), 0));  
    519. }
    520.  
    521. function DrawWeapon(){
    522.     draw = true;
    523.     canSwicthMode = false;
    524.     audio.clip = soundDraw;
    525.     audio.Play();
    526.     weaponAnim.animation.Play("Draw", PlayMode.StopAll);
    527.     weaponAnim.animation.CrossFade("Draw");
    528.     yield WaitForSeconds(drawTime);
    529.     draw = false;
    530.     reloading = false;
    531.     canSwicthMode = true;
    532.     selected = true;
    533.    
    534. }
    535.  
    536. function Deselect(){
    537.     selected = false;
    538.     mainCamera.camera.fieldOfView = 60;
    539.     weaponCamera.camera.fieldOfView = 50;
    540.     transform.localPosition = hipPosition;
    541. }
    542.  
     
  16. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    Uhg.. I mean its not SUPER important... but it does need some edits.. (clip sizes for snipers ect)
     
  17. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    This is a script that is doing nothing.. (Sniper Script)
    Code (JavaScript):
    1. /**
    2.  
    3. enum FireMode { semi, auto }
    4. var Mode = FireMode.semi;
    5.  
    6.     var soundFire : AudioClip;
    7.     var soundReload : AudioClip;
    8.     var soundEmpty : AudioClip;
    9.     var soundDraw : AudioClip;
    10.     var weaponAnim : GameObject;
    11.    
    12.     var Concrete : GameObject;
    13.     var Wood : GameObject;
    14.     var Metal : GameObject;
    15.     var Dirt : GameObject;
    16.     var Blood : GameObject;
    17.     var untagged : GameObject;
    18.  
    19.     var layerMask : LayerMask;
    20.     var muzzleFlash : Renderer;
    21.     var muzzleLight : Light;
    22.    
    23.     var damage : int = 50;
    24.     var bulletsPerMag : int = 50;
    25.     var magazines : int = 5;
    26.     var reloadTime = 2;
    27.     var drawTime = 1.0;
    28.     private var bulletsLeft = 0;
    29.     var fireRate : float = 0.1;
    30.     var range : float = 1000;
    31.     var force : float = 500;
    32.  
    33.     //Weapon accuracy
    34.     private var baseInaccuracy : float;
    35.     var inaccuracyIncreaseOverTime : float = 0.01;
    36.     var inaccuracyDecreaseOverTime : float = 0.5;
    37.     private var maximumInaccuracy : float;
    38.     private var triggerTime : float = 0.05;
    39.     var baseInaccuracyAIM : float = 0.005;
    40.     var baseInaccuracyHIP : float = 1.5;
    41.     var maxInaccuracyHIP : float = 5.0;
    42.     var maxInaccuracyAIM : float = 1.0;
    43.    
    44.     //Aiming
    45.     var hipPosition : Vector3;
    46.     var aimPosition : Vector3;
    47.     private var aiming : boolean;
    48.     private var curVect : Vector3;
    49.     var aimSpeed : float = 0.25;
    50.     var scopeTime : float;
    51.     private var inScope : boolean = false;
    52.     var scopeTexture : Texture;
    53.    
    54.     //Field Of View
    55.     var zoomSpeed : float = 0.5;
    56.     var FOV : int = 40;
    57.    
    58.     //KickBack
    59.     var kickGO : Transform;
    60.     var kickUpside : float = 0.5;
    61.     var kickSideways : float = 0.5;
    62.    
    63.     //GUI
    64.     var mySkin : GUISkin;
    65.     private var m_LastFrameShot : int = -1;
    66.     private var nextFireTime = 0.0;
    67.     private var reloading : boolean;
    68.     private var draw : boolean;
    69.     var weaponCamera : GameObject;
    70.     var mainCamera : GameObject;
    71.     private var player : GameObject;
    72.     @HideInInspector
    73.     var selected : boolean = false;
    74.     private var isFiring : boolean = false;
    75.     private var playing : boolean = false;
    76.    
    77.         //Crosshair Textures
    78.     var crosshairFirstModeHorizontal : Texture2D;
    79.     var crosshairFirstModeVertical : Texture2D;
    80.     private var adjustMaxCroshairSize : float = 6.0;
    81.    
    82. function Start(){
    83.     weaponCamera = GameObject.FindWithTag("WeaponCamera");
    84.     mainCamera = GameObject.FindWithTag("MainCamera");
    85.     player = GameObject.FindWithTag("Player");
    86.     muzzleFlash.enabled = false;
    87.     muzzleLight.enabled = false;
    88.     bulletsLeft = bulletsPerMag;
    89.     aiming = false;
    90. }  
    91. function Update() {
    92.     if(selected){
    93.    
    94.         if(Input.GetButtonDown ("Fire")){
    95.             if(Mode == FireMode.semi){
    96.                 fireSniper();
    97.             }
    98.            
    99.             if(bulletsLeft > 0)
    100.             isFiring = true;
    101.         }
    102.        
    103.         if (Input.GetButton ("Fire")){
    104.             if(Mode == FireMode.auto){
    105.                 fireSniper();
    106.                 if(bulletsLeft > 0)
    107.                 isFiring = true;
    108.             }  
    109.         }
    110.        
    111.         if (Input.GetButtonDown ("Reload")){
    112.             Reload();
    113.         }
    114.         if (Input.GetButton("Fire2") && !Input.GetButton("Run") && !reloading){      
    115.             if (!aiming){
    116.                 aiming = true;
    117.                 curVect = aimPosition - transform.localPosition;
    118.                 scopeTime = Time.time + aimSpeed;
    119.             }
    120.  
    121.             if (transform.localPosition != aimPosition && aiming){
    122.                 if(Mathf.Abs(Vector3.Distance(transform.localPosition , aimPosition)) < curVect.magnitude/aimSpeed * Time.deltaTime){
    123.                     transform.localPosition = aimPosition;
    124.                 } else {
    125.                     transform.localPosition += curVect/aimSpeed * Time.deltaTime;                  
    126.                 }
    127.             }
    128.            
    129.             if (Time.time >= scopeTime && !inScope){
    130.                 inScope = true;
    131.                 var gos = GetComponentsInChildren(Renderer);
    132.                     for( var go : Renderer in gos){
    133.                         go.renderer.enabled = false;
    134.                     }
    135.                 }
    136.  
    137.         } else {
    138.             if (aiming){
    139.                 aiming = false;
    140.                 inScope = false;
    141.                 curVect= hipPosition-transform.localPosition;
    142.                 var go = GetComponentsInChildren(Renderer);
    143.                 for( var g : Renderer in go){
    144.                 if (g.name != "muzzle_flash")
    145.                     g.renderer.enabled = true;
    146.                 }
    147.             }
    148.            
    149.             if(Mathf.Abs(Vector3.Distance(transform.localPosition , hipPosition)) < curVect.magnitude/aimSpeed*Time.deltaTime){
    150.                 transform.localPosition = hipPosition;
    151.             }else{
    152.                 transform.localPosition += curVect/aimSpeed*Time.deltaTime;
    153.             }
    154.         }
    155.        
    156.         if(inScope){
    157.             maximumInaccuracy = maxInaccuracyAIM;
    158.             baseInaccuracy = baseInaccuracyAIM;
    159.             mainCamera.camera.fieldOfView -= FOV * Time.deltaTime/zoomSpeed;
    160.             if(mainCamera.camera.fieldOfView < FOV){
    161.                 mainCamera.camera.fieldOfView = FOV;
    162.             }
    163.             weaponCamera.camera.fieldOfView -= 40 * Time.deltaTime/zoomSpeed;
    164.             if(weaponCamera.camera.fieldOfView < 40){
    165.                 weaponCamera.camera.fieldOfView = 40;
    166.             }
    167.         }else{
    168.             maximumInaccuracy = maxInaccuracyHIP;
    169.             baseInaccuracy = baseInaccuracyHIP;
    170.             mainCamera.camera.fieldOfView += 60 * Time.deltaTime/0.2;
    171.             if(mainCamera.camera.fieldOfView > 60){
    172.                 mainCamera.camera.fieldOfView = 60;
    173.             }
    174.             weaponCamera.camera.fieldOfView += 50 * Time.deltaTime/0.2;
    175.             if(weaponCamera.camera.fieldOfView > 50){
    176.                 weaponCamera.camera.fieldOfView = 50;
    177.             }
    178.         }
    179.  
    180.         if(player.rigidbody.velocity.magnitude > 3.0){
    181.             triggerTime += inaccuracyDecreaseOverTime;
    182.         }
    183.  
    184.         if(isFiring){
    185.             triggerTime += inaccuracyIncreaseOverTime;
    186.         }else{
    187.             if(player.rigidbody.velocity.magnitude < 3.0)
    188.             triggerTime -= inaccuracyDecreaseOverTime;
    189.         }
    190.    
    191.         if (triggerTime >= maximumInaccuracy) {
    192.             triggerTime = maximumInaccuracy;
    193.         }
    194.    
    195.         if (triggerTime <= baseInaccuracy) {
    196.             triggerTime = baseInaccuracy;
    197.         }
    198.        
    199.         if(nextFireTime > Time.time){
    200.             isFiring = false;
    201.         }
    202.     }
    203. }
    204.  
    205. function LateUpdate(){
    206.     if (m_LastFrameShot == Time.frameCount && !inScope){
    207.         muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward);
    208.         muzzleFlash.enabled = true;
    209.         muzzleLight.enabled = true;      
    210.     }else{
    211.         muzzleFlash.enabled = false;
    212.         muzzleLight.enabled = false;
    213.     }  
    214. }
    215.    
    216. function OnGUI (){
    217.     if(selected){
    218.         GUI.skin = mySkin;
    219.         var style1 = mySkin.customStyles[0];
    220.        
    221.         if(selected){
    222.             GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80),"Bullets : ");
    223.             GUI.Label (Rect(Screen.width - 110,Screen.height-35,200,80),"" + bulletsLeft, style1);
    224.             GUI.Label (Rect(Screen.width - 80,Screen.height-35,200,80)," / " + magazines);
    225.         }
    226.        
    227.         if(scopeTexture != null && inScope){
    228.             GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height), scopeTexture, ScaleMode.StretchToFill);
    229.         }else{
    230.             if(crosshairFirstModeHorizontal != null){  
    231.                 var w = crosshairFirstModeHorizontal.width;
    232.                 var h = crosshairFirstModeHorizontal.height;
    233.                 position1 = Rect((Screen.width + w)/2 + (triggerTime * adjustMaxCroshairSize),(Screen.height - h)/2, w, h);
    234.                 position2 = Rect((Screen.width - w)/2,(Screen.height + h)/2 + (triggerTime * adjustMaxCroshairSize), w, h);
    235.                 position3 = Rect((Screen.width - w)/2 - (triggerTime * adjustMaxCroshairSize) - w,(Screen.height - h )/2, w, h);
    236.                 position4 = Rect((Screen.width - w)/2,(Screen.height - h)/2 - (triggerTime * adjustMaxCroshairSize) - h, w, h);
    237.                 if (!aiming) {
    238.                     GUI.DrawTexture(position1, crosshairFirstModeHorizontal);     //Right
    239.                     GUI.DrawTexture(position2, crosshairFirstModeVertical);     //Up
    240.                     GUI.DrawTexture(position3, crosshairFirstModeHorizontal);     //Left
    241.                     GUI.DrawTexture(position4, crosshairFirstModeVertical);        //Down
    242.                 }
    243.             }
    244.         }
    245.     }      
    246. }
    247.  
    248.  
    249. function fireSniper (){
    250.     if (reloading || bulletsLeft <= 0){
    251.         if(bulletsLeft == 0){
    252.             OutOfAmmo();
    253.         }      
    254.         return;
    255.     }
    256.    
    257.     if (Time.time - fireRate > nextFireTime)
    258.         nextFireTime = Time.time - Time.deltaTime;
    259.  
    260.         while(nextFireTime < Time.time){
    261.             fireOneBullet();
    262.             nextFireTime = Time.time + fireRate;
    263.     }
    264. }
    265.  
    266. function fireOneBullet (){
    267.     if (nextFireTime > Time.time || draw){
    268.         if(bulletsLeft <= 0){
    269.             OutOfAmmo();
    270.         }  
    271.         return;
    272.     }
    273.    
    274.     var direction = mainCamera.transform.TransformDirection(Vector3(Random.Range(-0.05, 0.05) * triggerTime/3, Random.Range(-0.05, 0.05) * triggerTime/3,1));
    275.     var hit : RaycastHit;
    276.     var position = transform.parent.position;
    277.  
    278.     if (Physics.Raycast (position, direction, hit, range, layerMask.value)) {
    279.    
    280.         var contact = hit.point;
    281.         var rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
    282.        
    283.         if (hit.rigidbody){
    284.             hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
    285.         }
    286.        
    287.         if(hit.transform.tag == "Fracture"){
    288.             hit.transform.GetComponent("SimpleFracture").Fracture(contact,direction, true);
    289.         }
    290.  
    291.         if (hit.transform.tag == "Untagged") {
    292.             var default1 = Network.Instantiate (untagged, contact, rotation, 0);
    293.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    294.             //default1.transform.parent = hit.transform;
    295.             //Network.Instantiate(untagged, contact, rotation, 0);
    296.         }
    297.        
    298.         if (hit.transform.tag == "Concrete") {
    299.             var bulletHole = Network.Instantiate (Concrete, contact, rotation, 0);
    300.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    301.             //bulletHole.transform.parent = hit.transform;
    302.         }  
    303.        
    304.         if (hit.transform.tag == "Wood") {
    305.             var woodHole = Network.Instantiate (Wood, contact, rotation, 0);
    306.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    307.             //woodHole.transform.parent = hit.transform;
    308.         }
    309.        
    310.         if (hit.transform.tag == "Metal") {
    311.             var metalHole = Network.Instantiate (Metal, contact, rotation, 0);
    312.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    313.             //metalHole.transform.parent = hit.transform;
    314.         }
    315.        
    316.        
    317.         if (hit.transform.tag == "Dirt") {
    318.             var dirtHole = Network.Instantiate (Dirt, contact, rotation, 0);
    319.             //hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    320.             //dirtHole.transform.parent = hit.transform;
    321.         }
    322.        
    323.         if (hit.transform.tag == "canBeUsed") {
    324.             hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    325.         }  
    326.        
    327.         if (hit.transform.tag == "Enemy") {
    328.             hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    329.            
    330.             yield WaitForSeconds(0.02);
    331.             var bloodHole = Instantiate (Blood, contact, rotation) as GameObject;
    332.             if(Physics.Raycast (position, direction, hit, range, layerMask.value)){
    333.                 if(hit.rigidbody){
    334.                     hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
    335.                 }
    336.             }  
    337.         }
    338.     }
    339.    
    340.     PlayAudioClip(soundFire, transform.position, 0.7);
    341.     m_LastFrameShot = Time.frameCount;
    342.  
    343.     weaponAnim.animation.Rewind("sniperFire");
    344.     weaponAnim.animation.Play("sniperFire");
    345.     bulletsLeft--;
    346.     KickBack();
    347. }
    348.  
    349. function OutOfAmmo(){
    350.     if(reloading || playing)
    351.     return;
    352.    
    353.     playing = true;
    354.     yield WaitForSeconds(0.2);
    355.     PlayAudioClip(soundEmpty, transform.position, 0.7);  
    356.     yield WaitForSeconds(0.2);
    357.     playing = false;
    358. }
    359.  
    360. function PlayAudioClip (clip : AudioClip, position : Vector3, volume : float) {
    361.     var go = new GameObject ("One shot audio");
    362.     go.transform.position = position;
    363.     var source : AudioSource = go.AddComponent (AudioSource);
    364.     source.clip = clip;
    365.     source.volume = volume;
    366.     source.pitch = Random.Range(0.95,1.05);
    367.     source.Play ();
    368.     Destroy (go, clip.length);
    369.     return source;
    370. }
    371.  
    372. function Reload (){
    373.     if(reloading)
    374.     return;
    375.    
    376.     reloading = true;
    377.     if (magazines > 0 && bulletsLeft < bulletsPerMag) {
    378.         weaponAnim.animation["Reload"].speed = 1.0;
    379.         weaponAnim.animation.Play("Reload", PlayMode.StopAll);
    380.         weaponAnim.animation.CrossFade("Reload");
    381.         audio.PlayOneShot(soundReload);
    382.         yield WaitForSeconds(reloadTime);
    383.         magazines --;
    384.         bulletsLeft = bulletsPerMag;
    385.     }
    386.     reloading = false;
    387. }
    388.  
    389. function DrawWeapon(){
    390.     draw = true;
    391.     audio.clip = soundDraw;
    392.     audio.Play();
    393.     weaponAnim.animation.Play("Draw", PlayMode.StopAll);
    394.     weaponAnim.animation.CrossFade("Draw");
    395.     yield WaitForSeconds(drawTime);
    396.     draw = false;
    397.     reloading = false;
    398.     selected = true;
    399. }
    400.  
    401. function KickBack() {
    402.     kickGO.localRotation = Quaternion.Euler(kickGO.localRotation.eulerAngles - Vector3(kickUpside, Random.Range(-kickSideways, kickSideways), 0));  
    403. }
    404.  
    405. function Deselect(){
    406.     selected = false;
    407.     mainCamera.camera.fieldOfView = 60;
    408.     weaponCamera.camera.fieldOfView = 50;
    409.     inScope = false;
    410.     transform.localPosition = hipPosition;
    411.     var go = GetComponentsInChildren(Renderer);
    412.     for( var g : Renderer in go){
    413.         if (g.name != "muzzle_flash")
    414.             g.renderer.enabled = true;
    415.     }
    416. }
    417.  
    418.  
    the snipers in game dont have 50 bulles or 5 clips..? What script could be doing this.. making weapons have their own data..?
     
  18. Kokumo

    Kokumo

    Joined:
    Jul 23, 2010
    Posts:
    416
    Let me see if I understood.
    The last script you posted, is all commented, doesn't it?... and despite of this, the sniper has its own values; am I right?

    If you drag the sniper into the scene, which values do you see? the "magic" values or those set by the script (and, in fact, what we are expecting)?

    Another thing you can do, is to search references of the WeaponScriptNEW. If another script is setting up values, it must be using a WeaponScriptNEW reference.
     
  19. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    When the sniper is brought into play without the weaponcode it wont shoot or show ammo, but it also has its own script thats not in use, (as i've posted above) I'm checking for reference now.
     
  20. Kokumo

    Kokumo

    Joined:
    Jul 23, 2010
    Posts:
    416
    Any news?
     
  21. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    Possibly set to an empty gameopbject.
     
  22. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    Hi, to tell the truth i don't remember. I think i used raycast to pickup everything (weapons and ammo).

    Script should be attached to game object which holds all weapons. Possible called "WeaponManager" or something like that.
    Thats the reply I got from the owner of the script
     
  23. Kokumo

    Kokumo

    Joined:
    Jul 23, 2010
    Posts:
    416
    If you don't remember, it's difficult to help you =/
     
  24. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    I found the script, I clicked on my nplayer (Network player) then went to the guns script and fond the list used in multiplayer then I've just clicked the weapon and changed its values :D
     
  25. Kokumo

    Kokumo

    Joined:
    Jul 23, 2010
    Posts:
    416
    ALL RIGHT!!!... congratulations.
    As you can see, sometimes the problem can be resolved by searching references!
     
  26. xXdragon15Xx

    xXdragon15Xx

    Joined:
    Aug 5, 2014
    Posts:
    28
    Now time to get the map done...