public void Attack(GameObject enemy)
{
if (Physics.CheckSphere(transform.position, attack_radius, enemy.layer))
{
if (attack_time == 0)
{
if (Input.GetMouseButtonDown(0) || this.gameObject.layer == 8)
{
enemy.GetComponent<CharacterInfo>().health -= damage;
attack_time = attack_cooldown;
}
}
}
if (attack_time > 0)
{
attack_time -= Time.deltaTime;
}
}
Above you find my code for an attack method I use in instances of my enemy class as well as my player class. This method is called every update, and the values within I have found to be accurate via sending the values to console and seeing what they are.
However, the Physics.CheckSphere() always returns false. All of my game objects have colliders and correct tags applied to them, yet Physics.CheckSphere() always returns false. Any ideas why?
Heres a screenshot of what the sphere looks like on my player (in the red) and overlaps my enemy in the blue:
