call the code through the last animation

well i need help if you can answer i will be grateful. my object is falling, and when it arrives at some point it reappears somewhere else random, I’m using this code, all right.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SpawnController : MonoBehaviour {

    public float maxHeight;    
    public float minHeight;    

    public float rateSpawn;    
    private float currentRateSpawn;

    public GameObject objectPrefab;     .
    public int maxSpawnObjects;    
    private List<GameObject> objectsList = new List<GameObject>();  

// Use this for initialization
void Start () {

        for (int i = 0; i < maxSpawnObjects; i++) {    
           
            objectsList.Add(Instantiate(objectPrefab));    
            objectsList[i].SetActive(false);    
        }
    }
// Update is called once per frame
void Update () {

        currentRateSpawn += Time.deltaTime;   
        if (currentRateSpawn >= rateSpawn) {    

            currentRateSpawn = 0;
            Spawn();   


        }


   
}

    private void Spawn() {   

        float randHeight = Random.RandomRange(maxHeight, minHeight);   

        for (int i = 0; i < maxSpawnObjects; i++) {    

            if (objectsList[i].activeSelf == false) {      .

                objectsList[i].transform.position = new Vector3(transform.position.x, randHeight, 0);   
                objectsList[i].SetActive(true);   
                break;
            }
        }
    }
}

but I need to change this script.

when i use my last animation i want to call a script call the random reappearance of my object, just that line of script.

Hello,

Not sure this is the right place, but in the animation window, you can add custom callbacks whenever you want

The documentation seems depracated, but the idea is the same. Add a small animation event by using the small white pen that you see. And let it call your piece of code :).
The animation AS to be on an object that contains the script, otherwise, it’s not going to work.

Have a good day.