How to move a character after an instantiation was destroyed

Hi everyone! I have a character that moves through a waypoint system and stops at a specific point, after which an object is instantiated. The instantiated object, after you click on it, is destroyed two seconds later and then the character should continue on its way but it does not, and the console does not identify any errors to let me know why it does not work. This is my script of my instantiated object manager, the first one stops the player in the desired point:

    public GameObject Player;
    public GameObject Arrow;
    bool arrowSpawned = false;
    
    void Update () 

{
    
            //it stops the player  in an intersection.

            if (arrowSpawned == false && Player.GetComponent<WayPointSystem>().waypointIndex == 4 || Player.GetComponent<WayPointSystem>().waypointIndex == 8 || Player.GetComponent<WayPointSystem>().waypointIndex == 15 || Player.GetComponent<WayPointSystem>().waypointIndex == 30)

            {
                Player.GetComponent<WayPointSystem>().moveAllowed = false;
                SpawnArrow();      
            }

 }

And this function instantiates the arrow where I want:

void SpawnArrow()
    {
        if (arrowSpawned == false)
        {
            Instantiate(Arrow, new Vector3(-1.9f, 1.6f, -7.5f), Quaternion.Euler(new Vector3(90,180,0)));
            
            arrowSpawned = true;
            var ArrowInstantiated = GameObject.FindGameObjectsWithTag("Arrow");
            
            if (ArrowInstantiated == null)
            {
               Player.GetComponent<WayPointSystem>().moveAllowed = true;
            }
        }
        
    }

The instantiated object has also a script that destroys the object when you click on it:

Animator Arrow;

    private void Start()
    {
        Arrow = GetComponent<Animator>();
    }

    private void OnMouseDown()
    {
        Arrow.SetTrigger("ArrowSelected");
        Destroy(gameObject, 2f);
    }

My problem is, in the function ‘SpawnArrow()’ that I showed you I’m trying to check if the arrow was already destroyed to let the player move. I’m using ‘FindGameObjectsWithTag (arrow)’, but it doesn’t work. Am I doing something wrong? What else can I do?

Thank you in advance for the whole community!

2 Answers

2

I cant understand your code, you are creating an arrow and 1 line after that you are checking if that same arrow was destroyed? the arrowinstantiated will never be null since you have just spawned it, or i am missing somethiing?

Good day.

I think the problem is that you are doing this:

var ArrowInstantiated = GameObject.FindGameObjectsWithTag("Arrow");

which returns an array. You should use

FindGameObjectWithTag() without S !!

Bye!