- Home /
Change WindZone settings in runtime?
I'm trying to make a script that changes my WindZone settings in runtime but it looks like Unity has the WindZone as private class. Is there any way to change those settings in runtime? I saw some projects doing that, any suggestions?
Ugly but possible:
http://forum.unity3d.com/threads/60593-Access-Terrain-Wind-Setting-and-Wind-Zone-in-Unity3D-3-0-02f
For many of the settings, you can emulate the effect by just rotating the transform of the WindZone game object.
Answer by knowpixels · Feb 25, 2015 at 02:16 PM
The WindZone DataType is private in Unity as of 3.x - this is still true as of 4.5.x This means you cannot access its properties using strict typing (#pragma strict) and typeof(). So if you try GetComponent(WindZone) or GetComponent(typeof(WindZone)) you will receive an unknown type error message from Unity Console. All you have to do is switch to dynamic typing, it is this easy:
Remove #pragma strict from the top of your script.
Change any usage instance of GetComponent(WindZone) or GetComponent(typeof(WindZone)) to GetComponent("WindZone"); (Include speech marks!) and remove any var type declartions.
So instead of:
#pragma strict
var wz:WindZone = GetComponent(WindZone);
Your script should look like:
//#pragma strict
var wz = GetComponent("WindZone");
Now the unknown type error in Unity console will be gone and your script has access to WindZone script properties through the var called "wz" you can now do:
wz.windMain = 1;
wz.windTurbulence = 1.2;
wz.windPulseMagnitude= 0.6;
wz.windPulseFrequency= 0.2;
Or what ever you need for runtime visibility and control of in game blustery goodness. I hope someone finds this comment useful.