Answer the question
In order to leave comments, you need to log in
TakeDamage triggered?
what needs to be changed in order for TakeDamage to work
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossWeapon : MonoBehaviour
{
[SerializeField] private float damage;
public int enragedAttackDamage = 40;
public Vector3 attackOffset;
public float attackRange = 1;
public LayerMask attackMask;
public void Attack()
{
Vector3 pos = transform.position;
pos += transform.right * attackOffset.x;
pos += transform.up * attackOffset.y;
Collider2D colision = Physics2D.OverlapCircle(pos, attackRange, attackMask);
if (colision.tag == "Player")
{
colision.GetComponent<Health>().TakeDamage(damage);
}
}
public void EnragedAttack()
{
Vector3 pos = transform.position;
pos += transform.right * attackOffset.x;
pos += transform.up * attackOffset.y;
Collider2D colInfo = Physics2D.OverlapCircle(pos, attackRange, attackMask);
if (colInfo != null)
{
//colInfo.GetComponent<PlayerHealth>().TakeDamage(enragedAttackDamage);
}
}
void OnDrawGizmosSelected()
{
Vector3 pos = transform.position;
pos += transform.right * attackOffset.x;
pos += transform.up * attackOffset.y;
Gizmos.DrawWireSphere(pos, attackRange);
}
}
Answer the question
In order to leave comments, you need to log in
Uncomment, check if there is a Player tag on the object with the Health script, make sure that you assign attackMask somewhere, because I don’t see it in the code. Make sure the problem isn't that the radius of the sphere is too small. And it is also necessary to write a check of your collision for null in the code, otherwise there will be an error.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question