- Home /
Question by
NewtNoot0114 · Apr 20, 2020 at 08:51 AM ·
nullreferenceexceptioncombat
Basic Combat System errorNullReferenceException: Object Reference not set to an instance of an object.
Im having issues on line 38 where it will not detect the others hitbox, I'm not quite sure what is happening to it.
public class PlayerAttack : MonoBehaviour { private float timeBtwAttack; public float startTimeBtwAttack;
public Transform attackPos;
public float attackRangeX;
public float attackRangeY;
public int damage;
public LayerMask enemy;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (timeBtwAttack <= 0)
{
//resets attack timer
timeBtwAttack = startTimeBtwAttack;
//attacks
if (Input.GetMouseButtonDown(0))
{
Collider2D[] enemiesToDamage = Physics2D.OverlapBoxAll(attackPos.position, new Vector2(attackRangeX, attackRangeY), 0);
for (int i = 0; i < enemiesToDamage.Length; i++)
{
enemiesToDamage[i].GetComponent<enemymover>().TakeDamage(damage);
}
}
}
else {
timeBtwAttack -= Time.deltaTime;
}
}
}
Comment