#Override method not working

1 messages · Page 1 of 1 (latest)

maiden mesa
#

I have this code in a child class but for some reason my override method is not getting called

{
    public override void Interact()
    {
        base.Interact();

        PickUpItem();
    }

    void PickUpItem()
    {
        Debug.Log("Picked up item");
        Destroy(gameObject);
    }
}


#

Parent Class code:

    {
        Debug.Log("Interacting with " + transform.name);
    }
#

When I interact with an object that has the ItemPickup script assigned to it. it performs the function of the base method in the parent class but not the child class

maiden mesa
#

What do you mean?

turbid mica
#

Where do you call the method?

neat moss
#

Not sure how to be more clear about that...

turbid mica
#

So you only get one log?

maiden mesa
turbid mica
#

Again, show where you're calling Interact . . .

maiden mesa
#

the code I have above are the only 2 instances of the method being called

neat moss
#

Sounds like you're just not calling it at all probably

neat moss
maiden mesa
#

My update method in the parent class could be messing it up

neat moss
#

??

maiden mesa
#
    {
        if (isFocused && !interacted)
        {
            float distance = Vector3.Distance(player.position, interactionPoint.position);
            if(distance <= interactionRadius)
            {
                Debug.Log("Interact");
                interacted = true;
            }
        }
    }``` 

yeah this is whats actually being called, so instead of the Debug line here, i would call the Interact method?
neat moss
#

You need to actually call Interact() on something

turbid mica
#

Do you know how to call a method?

neat moss
#

If you want it to run

turbid mica
maiden mesa
#

Alright replace the debug line with the Update method call fixed it