#Issue with heritance

1 messages · Page 1 of 1 (latest)

exotic swift
#

I've made a hitbox system with the following script

    PlayerStatManager statManager;

    public float hitboxRad;

    private void Update()
    {
        RaycastHit2D hit;
        CoreAliveObject alive;  
        
        hit = Physics2D.CircleCast(transform.position, hitboxRad,Vector2.right,0f,statManager.playerData.canHit); <-- This Line
        hit.transform.TryGetComponent(out alive);

        if (alive != null)
        {
            alive.TakeDamage(statManager.playerData.attack1Dmg);
        }
    }

    private void OnDrawGizmos()
    {
        Gizmos.DrawWireSphere(transform.position, hitboxRad);   
    }

im trying to hit an enemy that inherites from CoreAliveObject and it is giving me a nullReferenceException on the highlighted line, ive tried everything and I cant figure out why it isnt working, any ideas?

#

the layermask works because I've got a separate function using the same layermask and the same method inheriting from the same thing and its still not working

#

the only difference is that the one that works uses a raycast and this uses a circleCast

solemn bone
#

The only part that I see could be null in that cast would be your statManager, which it doesnt look like youve assigned anywhere in the code youve shown