- Home /
Physics2d overlap point sends exception on attempting to find player
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CanDamage : Damageable
{
protected int damageDealt;
protected void DealDamage(Vector2 pos)
{
GameObject hittingObj;
Debug.Log(Physics2D.OverlapPoint(pos).gameObject);
if (Physics2D.OverlapPoint(pos).gameObject != null)
{
hittingObj = Physics2D.OverlapPoint(pos).gameObject;
hittingObj.SendMessage("Damage", damageDealt);
}
else
{
hittingObj = gameControl.getPlayer();
hittingObj.SendMessage("Damage", damageDealt);
}
}
}
My player and enemy both use this code to deal damage. My player can detect enemies just fine with it and it works perfectly. However, if the enemy attempts to use it it will send an exception when it tries to do Physics2D.OverlapPoint(pos).gameObject
. I'm not sure why this is, I tried to see if the position getting sent to the method is correct and it is. Idk why this won't work.
Comment