Disabling Weapon Switching script, when Reloading?

I basically want the weapon switching script (PlayerWeapons) to be disabled when and ONLY when reloading is happening (in the MachineGun Script) The code is right, im just getting an error:
BCE0005: Unknown identifier: ‘setEnableWeaponSwitch’.

This is my weapon switching script(PlayerWeapons)

private var b_enabled : boolean = false;

function Start () { 
   // Select the first weapon 
   SelectWeapon(0); 
} 

function Update () { 
if (b_enabled){
   // Did the user press fire? 
   if (Input.GetButton ("Fire1")) 
      BroadcastMessage("Fire"); 
    
   if (Input.GetKeyDown("1")) { 
      SelectWeapon(0); 
   }    
   else if (Input.GetKeyDown("2")) { 
      SelectWeapon(1); 
	  }
   }    
} 

function SelectWeapon (index : int) { 
   for (var i=0;i<transform.childCount;i++)   { 
      // Activate the selected weapon 
      if (i == index) 
         transform.GetChild(i).gameObject.SetActiveRecursively(true); 
      // Deactivate all other weapons 
      else 
         transform.GetChild(i).gameObject.SetActiveRecursively(false); 
   } 
}

public function setEnableWeaponSwitch(b_enabled_fp : boolean) { 
    b_enabled = b_enabled_fp; //the "fp" stands for "function parameter" 
}

And my MachineGun Script:

var range = 200.0; 
var fireRate = 0.05; 
var force = 10.0; 
var damage = 5.0; 
var bulletsPerClip = 100; 
var clips = 5;
var reloadTime = 5; 
private var hitParticles : ParticleEmitter; 
var muzzleFlash : Renderer; 
static var bulletsLeft : int = 0; 
static var clipsLeft : int = 0;
private var nextFireTime = 0.0; 
private var m_LastFrameShot = -1; 
function Start () { 

   hitParticles = GetComponentInChildren(ParticleEmitter); 
   // We don't want to emit particles all the time, only when we hit something. 
   if (hitParticles) 
      hitParticles.emit = false; 
   bulletsLeft = bulletsPerClip; 
} 

function LateUpdate() { 
  // if(Input.GetButtonDown("Reload")) 
  // Reload();
	  
   if (muzzleFlash) { 
      // We shot this frame, enable the muzzle flash 
      if (m_LastFrameShot == Time.frameCount) { 
         muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward); 
         muzzleFlash.enabled = true; 

         if (audio) { 
            if (!audio.isPlaying) 
               audio.Play(); 
            audio.loop = true; 
         } 
      } else { 
      // We didn't, disable the muzzle flash 
         muzzleFlash.enabled = false; 
         enabled = false; //<---- enable true if you want to reload manually, but with no reload time.
          
         // Play sound 
         if (audio) 
         { 
            audio.loop = false; 
         } 
      } 
   } 
} 
function Fire () { 
   if (bulletsLeft == 0) {
     ///Reload();
     return; 
    }
	
   // If there is more than one bullet between the last and this frame, Reset the nextFireTime 
   if (Time.time - fireRate > nextFireTime) 
      nextFireTime = Time.time - Time.deltaTime; 
    
   // Keep firing until we used up the fire time 
   while( nextFireTime < Time.time  bulletsLeft != 0) { 
      FireOneShot(); 
      nextFireTime += fireRate; 
   } 
} 
function FireOneShot () { 
   var direction = transform.TransformDirection(Vector3.forward); 
   var hit : RaycastHit; 
    
   // Did we hit anything? 
   if (Physics.Raycast (transform.position, direction, hit, range)) { 
      // Apply a force to the rigidbody we hit 
      if (hit.rigidbody) 
         hit.rigidbody.AddForceAtPosition(force * direction, hit.point); 
        
      // Place the particle system for spawing out of place where we hit the surface! 
      // And spawn a couple of particles 
      if (hitParticles) { 
         hitParticles.transform.position = hit.point; 
         hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal); 
         hitParticles.Emit(); 
      } 

      // Send a damage message to the hit object          
      hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver); 
   } 
//decrease bullets by 1.
   bulletsLeft--; 
   // Register that we shot this frame, so that the LateUpdate function enabled the muzzleflash renderer for one frame 
   m_LastFrameShot = Time.frameCount; 
   enabled = true; 
    
   //gun reload in time 
if(bulletsLeft == 0) 
     Reload(); 
	 
} 

function Reload (){ 
SendMessageUpwards(setEnableWeaponSwitch, false);
//audio.PlayOneShot(reloadSound, 1.0 / audio.volume);

//    Wait for reload time first - then add more bullets! 
yield WaitForSeconds(reloadTime); 
   
   // We have a clip left reload 
 if (clips > 0 ) { 

   clips--;
     bulletsLeft = bulletsPerClip; 
	}//else {
	// clips = clips;
 //}
SendMessageUpwards(setEnableWeaponSwitch, true);
} 


function GetBulletsLeft () { 
   return bulletsLeft; 
}

function GetClipsLeft () {
return clips;
}

Any ideas?

Bump. Anyone?

just get the component of the select weapons script and disable it whenever reload is true.

Hmm, i tried doing that, but it didnt work, im not sure if i did it right, how would i write that script?

assuming the first script in ur thread named “PlayerWeapons” so :

if(reload){
var test : PlayerWeapons = GameObject.Find("The GameObject With PlayerWeapons Attach To").GetComponent(PlayerWeapons);
test.enabled = false;
}

*If ur gameobject is a child then look at this e.g. :
assuming the gameobject that the playerweapons script attach to named “bla” which is a child of “blaMain” so it’d be :

 if(reload){
var test : PlayerWeapons = GameObject.Find("blaMain/bla").GetComponent(PlayerWeapons);
test.enabled = false;
}

*You put the script in the 2nd script u provided in the thread.

Well i solved my issue using the disable component, turns out i just needed to added quotes SendMessageUpwards("setEnableWeaponSwitch", false);

Thanks for your help anyway creative :slight_smile:

Oh, That’s another way of doing that, I just didn’t read ur code :wink:

Yeah its much easier that way, thanks anyways, you think you could help me here? http://forum.unity3d.com/viewtopic.php?p=322559#322559 shudnt be too hard to find a way to fix this. Thanks.