I started a new side scrolling game on Unity, and after watching a video based off of player combat, I'm stuck on an error that I cant fix. I'm very new to coding, so I have no Idea how to solve it. I haven't been able to finish the 2 scripts because I can't play the game until it is fixed. Here is my 2 scripts, and the video I watched: https://youtu.be/sPiVz1k-fEs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCombatScript : MonoBehaviour
{
public Animator animator;
public Transform attackPoint;
public float attackRange = 0.5f;
public LayerMask enemyLayers;
public int attackDamage = 40;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0)) // Check if left mouse button is being pressed.
{
Attack();
}
}
void Attack()
{
// Play an attack animation.
animator.SetTrigger("Attack");
// Detect enemies in range of attack.
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
// Damage them.
foreach(Collider2D enemy in hitEnemies)
{
Debug.Log("We hit" + enemy.name);
enemy.GetComponent<enemy>().TakeDamage(attackDamage);
}
}
void OnDrawGizmosSelected()
{
if (attackPoint == null)
return;
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy1 : MonoBehaviour
{
public int maxHealth = 100;
int currentHealth;
// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth;
}
public void TakeDamage(int damage)
{
currentHealth -= damage;
// Play hurt animation
if(currentHealth <= 0)
{
Die();
}
}
void Die()
{
Debug.Log("Enemy died!");
// Die animation
// Disable the enemy
}
}
This is the full error message: Assets\PlayerCombatScript.cs(35,32): error CS0118: 'enemy' is a variable but is used like a type.