- Home /
How I am making a top down 2d combat script. When the players right attack point touches an object in the enemylayer it will take damage(Testing), but it is not working how do I fix that?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class enemyDetectionScript : MonoBehaviour { public Transform attackPointRight; public playerInfo playerInfo;
public LayerMask enemyLayer;
// Start is called before the first frame update
void Start()
{
attackPointRight.parent = null;
}
// Update is called once per frame
void Update()
{
// Checks for colliders
if (!Physics2D.OverlapCircle(attackPointRight.position, 0.2f, enemyLayer))
{
playerInfo.currentHealth -= 10;
}
}
}
Comment
I believe you are currently checking if there is not a collision. Try removing ! also add in Debug.Log() statements to find out what is going on.