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.

2d melee combat error

Discussion in 'Visual Scripting' started by Orioryx, Oct 23, 2020.

  1. Orioryx

    Orioryx

    Joined:
    Oct 23, 2020
    Posts:
    3
    so im new to unity and i made this code from brackeys tutorial:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerCombat : MonoBehaviour {
    6.     public Animator animator;
    7.     public float AttackRange = 0.5f;
    8.     public Transform AttackPoint;
    9.     public LayerMask EnemyLayers;
    10.     // Update is called once per frame
    11.     void Update()
    12.     {
    13.         if (Input.GetMouseButtonDown(0))
    14.         {
    15.             Attack();
    16.         }
    17.     }
    18.  
    19.     void Attack()
    20.     {
    21.         //Play an attack animation
    22.         animator.SetTrigger("Attack");
    23.         //Detect enemies in range of attack
    24.         Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(AttackPoint.position, AttackRange, EnemyLayers);
    25.         //Deal damage
    26.         foreach(Collider2D enemy in hitEnemies)
    27.         {
    28.             Debug.Log("We hit" + enemy.name);
    29.         }
    30.     }
    31.  
    32.     void OnDrawGizmosSelected()
    33.     {
    34.         if (AttackPoint == null)
    35.             return;
    36.  
    37.        
    38.  
    39.         Gizmos.DrawWireSphere(AttackPoint.position, AttackRange);
    40.     }
    41. }
    but it doesnt debug log that i hit my slime enemy that i have placed.
     
  2. Orioryx

    Orioryx

    Joined:
    Oct 23, 2020
    Posts:
    3
    nvm i fixed it