Mecanim Boolean Not Working

So i’ve got a boolean called WeaponIsOn, and if the boolean is true, then the hand would clench, like it’s holding a weapon, and when i click left mouse button it would swing. If it’s off then it would unclench, and if i click left mouse button it would punch. I have a script that does this for me. I have attached the animator to the variable, and I’m sure it’s the right animator. Here are some parts of the script (JavaScript):

Declare the variable:

var theAnimator : Animator;

WeaponIsOn:

for (var i = 0 ; i < transform.childCount ; i++)
	{
		//Activate selected weapon
		if (i == index)
		{
			if (transform.GetChild(i).name == "Fists")
			{
				theAnimator.SetBool("WeaponIsOn", false);

			}
			
			else
			{
				theAnimator.SetBool("WeaponIsOn", true);
			}
			
			transform.GetChild(i).gameObject.SetActive(true);
		}
		
		else
		{
			transform.GetChild(i).gameObject.SetActive(false);
		}
	}

The parent object is melee, and the child objects are knife and Fists. This works with the clenching/unclenching. when there isn’t a weapon equipped and i click left mouse button, it punches, but when it has a weapon and i click left mouse button, it doesnt swing. The two booleans for the 2 hits are Hit01 and Hit02. Here’s the script for the hitting:

#pragma strict

var TheDamage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheAnimator : Animator;
var DamageDelay : float = 0.4;

var Hit01Streak = 0;
var Hit02Streak = 0;

function Update ()
{
	if (Input.GetButtonDown("Fire1"))
	{
		AttackDamage();
	}
	
	if (Input.GetKey(KeyCode.W))
	{
		TheAnimator.SetBool("IsRunning", true);
	}
	
	else
	{
		TheAnimator.SetBool("IsRunning", false);
	}
}

function AttackDamage ()
{
	if (Random.value >= 0.5  Hit01Streak <= 2)
	{
		TheAnimator.SetBool("Hit01", true);
		Hit01Streak += 1;
		Hit02Streak = 0;
	}
	
	else
	{
		if (Hit02Streak <= 2)
		{
			TheAnimator.SetBool("Hit02", true);
			Hit01Streak = 0;
			Hit02Streak += 1;
		}
		
		else
		{
			TheAnimator.SetBool("Hit01", true);
			Hit01Streak += 1;
			Hit02Streak = 0;
		}
	}
	
	yield WaitForSeconds(DamageDelay);
	//Actual Attacking
	var hit : RaycastHit;
	var ray = Camera.main.ScreenPointToRay(Vector3(Screen.width / 2, Screen.height / 2, 0));
	
	if (Physics.Raycast (ray, hit))
	{
		Distance = hit.distance;
		
		if (Distance < MaxDistance)
		{
			hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
		}
	}
	
	TheAnimator.SetBool("Hit01", false);
	TheAnimator.SetBool("Hit02", false);
}

(This code and the other code are different scripts0
If anyone can give me a solution to this and why, I would be very grateful, thanks :slight_smile:

Never Mind People, I’ve fixed it. it was a simple and silly mistake of mine. I didnt attach one of the scripts to the melee object

I’m having the exact same issue. I’ve watched and rewatched Brackey’s tutorials, but can’t seem to get this thing working. The Melee object has the WeaponSwitch script attached to it, and it also has the Fists object as child (Fists has the Weapons script, so the arms can punch when no weapon is equipped). Every time I equip a weapon, the bool WeaponIsOn doesn’t become true in the Animator… So frustrating. I have to mention, that the weaponversions are childs of the Fists object every time a weapon is equipped. Should they be childs of the Melee object?