Change all GameObjects with tag "StopUse" to "Platform" when i press a button.

I need to somehow change all my gameobjects with the tag “StopUse” to “Platform” whenever i press R because when my bullet hits a platform it is suppose to change the tag to “StopUse” as this was an fix with a bug i had. So when i press R to reset my map i need the platforms with the tag “StopUse” back to “Platform”

Something that temporarily changes the tag could also help.

Thankful for any help :slight_smile:

You could use the method described in this link: Unity - Scripting API: GameObject.FindGameObjectsWithTag

You declare a list of game objects, and have the list receive the result of the FindGameObjectsWithTag() method. After this you can simply do a foreach loop in which you change the tags manually. Something like this (not tested):

private GameObject[] stopUseTagObjects;

void Update() 
{
    if (Input.GetKeyDown(KeyCode.R)) 
    {
        ChangeTagToPlatform();
    }
}

void ChangeTagToPlatform()
{
    stopUseTagObjects = GameObject.FindGameObjectsWithTag("StopUse");
    
    foreach (GameObject stopUse in stopUseTagObjects) 
    {
        stopUse .tag = "Platform";
    }

}

Searching game objects like this is not really optimal, but I guess it is the easiest way to change all of them without having to assign a different script to each object. If you care more about performance than the trouble in doing it, attach a script in all your objects that have the tag “StopUse”, in a way that the script checks if the current tag is “StopUse” and if there is a press on the button, if so you simply change the tag manually to “Platform”… Like this:

void Update() 
{
    if (Input.GetKeyDown(KeyCode.R)) 
    {
        if (this.gameObject.tag == "StopUse) 
        {
            this.gameObject.tag = "Platform";
        }
    }
}