- Home /
how do i get a public variable from another script
I have a public variable calles bounds in a script called scr_findbounds, which is attached to a gameobject. I've tried several things and googled for hours but I can't find a solution.
I thought maybe something like this:
width = GameObject.Find("field1").GetComponent().bounds;
or this:
width = GameObject.Find("field1").GetComponent("scr_findbounds").bounds;
it seems to be easy in java but I can't get it to work in c#, does anyone know how to do this?
Comment
Answer by whydoidoit · Aug 20, 2012 at 04:10 PM
You need to get the actual type of the component in C# which means using the generic version of GetComponent rather than the string version:
width = GameObject.Find("field1").GetComponent<scr_findbounds>().bounds;