unable to attack enemy objects?

I’ve been working in the 2d roguelike tutorial, and after finishing it, I’m going through and adding some more features to it to make it my own thing, and learn more about coding.

I’m trying to add a feature to allow the player to attack the enemy characters, which is set up the same as both of the functions for attacking walls, and enemies attacking the player, but when the character moves towards an enemy space, he doesn’t attack at all.

The only difference is that I’ve set up an item that the player must collect on each level before he can attack enemies, which is just a boolean, called “hasAxe” I’ve set to public temporarily so I can verify that it’s triggering correctly in the inspector.

Does anyone know why this is failing? there’s no runtime error in the console.

attack function in the player script:

if(component.GetType() == typeof(Enemy))
			if (hasAxe == false)
			else if (hasAxe == true)

				//Declare hitEnemy and set it to equal the encountered component.
				Enemy hitEnemy = component as Enemy;

				//Call the EnemyHit function of hitEnemy passing it axeDamage, the amount of healthpoints to be subtracted.

				//play the chop sound
				SoundManager.instance.RandomizeSfx (chopSound1, chopSound2);

				//Play the axe animation
				animator.SetTrigger ("playerAxe");	

Enemy Damage code:

	public void LoseHealth (int loss)
		//Subtract lost food points from the players total.
		enemyHealth -= loss;

	private void CheckForDeath()
		if (enemyHealth <=0)
			gameObject.SetActive (false);

at this point, the code gets a little long to feel comfortable posting all of it to display on a webpage, so I’m going to throw the scripts in pastebin.

Player Script:

Enemy Script:

Wall Script:

MovingObject(parent of Player and Enemy):

Hi there,

I am struggling with a similar issue. I tried copying as much of the system used in the wall script but can’t get it to work.
What I did was assign a second script to the Enemy1 and 2 prefab which is basically a copy of the wallscript. Everything in the player script and the copy of the wall script (assigned to the enemy1 and 2) of course has unique names usually just by replacing the word “wall” with “enemy”. I also tried adding the concept used in wall script to the enemy script but that also didn’t work.
Have you found a solution yet? Of course I can elaborate further if requested.