- Home /
using a string variable as an argument in gameobject.find() does not work ?
i need to search for a name that that is is stored in a variable but apparently i cannot use a string as the argument in gameobject.find
isnt gameobject.find required to use a string?
this code returns the error error CS0176: Static member `UnityEngine.GameObject.Find(string)' cannot be accessed with an instance reference, qualify it with a type name instead
string finder; void Start () {
for(int o=0;o<10;o++){
for(int p=0;p<10;p++){
finder="x"+o+"y"+p;
GameObject hold =gameObject.Find(finder);
Destroy(hold);
print(finder);
}}}
Answer by BiG · Feb 13, 2012 at 01:00 PM
It's GameObject.Find, not gameObject.Find. Let me know if it's sufficient.
wow , i just hate that kind of spelling errors , i guess i still have to get used to c#
Visual Studio and C# is the way forward, don't know why people use JS, it really sucks.
Answer by Meltdown · Feb 13, 2012 at 01:01 PM
Although I don't use JS anymore try...
GameObject hold = GameObject.Find(finder.toString());
or
GameObject hold = GameObject.Find(finder.ToString());
Your answer
![](https://koobas.hobune.stream/wayback/20220613064034im_/https://answers.unity.com/themes/thub/images/avi.jpg)