I made a damage system so when an enemy collides with the raycast and you click it damages the enemy. but every time I put my sword on the player the damage system stops working and I tried to make the raycast ignore the sword but it won’t work.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyChecker : MonoBehaviour
{
[SerializeField] private float range;
public LayerMask sword;
public GameObject enemy;
private bool canSlash;
RaycastHit hit;
void FixedUpdate()
{
Vector3 fwd = transform.TransformDirection(Vector3.forward);
Vector3 back = transform.TransformDirection(Vector3.back);
Vector3 dwn = transform.TransformDirection(Vector3.down);
Vector3 up = transform.TransformDirection(Vector3.up);
Debug.DrawRay(transform.position, fwd * range, Color.green);
if (Physics.Raycast(transform.position, fwd,out hit, range -sword)&&hit.transform.tag == "Enemy")
{
if (Input.GetMouseButtonDown(0))
{
enemy.GetComponent<EnemyHealth>().TakeEDamage(5);
}
print("ObjectLocked");
}
}
}