Call another function from OnTargetReached()

I look at the documentation but I still couldn’t find out how to call a function from another script when the ailerp reaches its destination.
When the target is reached I can use Debug.log(“anything in here”) to see if it is called and it works fine, but I need to call some function from another script.

More details:
There are more function in the Spawner.cs script that I have made. For example there is a function called Identic(). It is set to public void and I tried to call it this way:

GameObject.Find("Main Camera").GetComponent<Spawner>.Identic();

But it doesn’t find my Spawner.cs script.

Can you please help me do it?

Hi

Don’t edit the pathfinding scripts directly. They will not be able to find any scripts outside the pathfinding package. Instead either write your own script which inherits from the one you want to change or just check the properties on the AILerp script.

For example

void Update () {
    if (GetComponent<AILerp>().reachedDestination) {
        // Do stuff
    }
}

See https://arongranberg.com/astar/docs/ailerp.html#reachedDestination

1 Like

Thank you very much, this did the work.