Home > Back-end >  having trouble passing variables between two game objects
having trouble passing variables between two game objects

Time:08-05

I have a bunch of soil patch game objects which can be turned into flowers. I want to click on flower and open up a new menu. But the soil patches get clicked accidentally when I click on the menu buttons. So I set up a bool so that the soil patches can be turned on and off.

Soil patch code has a bool active. This is what I'm doing in the flower code:

 void onm ouseDown()
    {
        public GameObject[] soilpatches= GameObject.FindGameObjectsWithTag("Soilpatch");
        foreach (GameObject soilpatch in soilpatches)
        {
            SoilPatch _soilpatch=soilpatch.GetComponent<SoilPatch>();
            _soilpatch.active=false;
        }
    }

But it keeps giving me compile errors.

EDIT: 'active' is a bool I've set up inside the soilpatch script.

CodePudding user response:

It was because I was declaring a public variable inside onm ouseDown()

CodePudding user response:

chage the last line to: _soilpatch.SetActive(false);

  • Related