Is there a way to switch between tags using a toggle?

    void Start()
    {
           thisComp = this.GetComponent<Toggle>();
           thisComp.onValueChanged.AddListener(delegate{SelectShape(thisComp);
           });
    }


    void Update()
    {

    }

    public void SelectShape(Toggle value)
    {

        nameOfObject = this.name;
        selectedObj = GameObject.Find(this.name);
        chooseDropDown = GameObject.FindWithTag("dropdown");
        chooseOptions = chooseDropDown.GetComponent<Dropdown>();

        if (chooseDropDown = GameObject.Find(nameOfObject))
            {
            if (chooseOptions.options[chooseOptions.value].text == "Resize Shapes")
                {
                    if (value.isOn)
                        {
                            Instantiate(cube);
                            selectedObj.tag = ("selected");
                        }

                     if (!value.isOn)
                        {  
                            Instantiate(cylinder);
                            selectedObj.tag = ("shapes");                         
                        }
                }
            }
    }

For some reason, when the toggle is on, the object switches tag to “selected”. But when the toggle is off, it does not go back to “shapes”. Any idea what I’m doing wrong?

Well, line 23 is an if check, but you only have a single =. Comparisons should have == . I’m not sure if this is enough to fix your bug, but try it.

1 Like

Thank you, fixed that but the problem persists :frowning:

I’ll be honest, your code is doing a lot of things and I’m not really sure what you’re trying to achieve. You need to add Debug.log calls through your code and see where it’s failing. Log the values of all those variables, what if statements are being hit or being missed. It’s difficult for someone to help because we don’t know what values you are getting or what you expect.

1 Like