- Home /
How do I disable a wind zone through script?
Does anyone know how to disable a wind zone through script? I have tried every enable/disable command and nothing works, unless there's a way to that I'm not aware of.
Please if anyone knows how it'd be great, since Unity doesn't allow us access the Wind Zone commands. I was just about to release a video of our new system and now I'm stuck with this problem.
Thanks
Answer by Kleptomaniac · Mar 11, 2012 at 01:34 AM
I've never used Wind Zones before, but having just looked at the Script Reference, could you not just set the Wind Main and Turbulence to 0?
Hope this helps, Klep
Yes, this is the problem, I don't think there is anyway to access the Wind Zone through script. I have already checked all the docs.
As is said here, WindZone is as of yet an inaccessible class. @Nividica provides a fairly hacky solution about a quarter of the way down the thread which renders it a public class, but obviously this isn't ideal. @Warwick Allison also provides an even less appealing solution to this problem here which uses animations to actually scale down the Wind $$anonymous$$ain and Turbulence, but again it's really one of the only ways of going about it under the current conditions. I for one would use the first solution from Nividica simply for the sake of convenience and consistency, but that's just choosing the least bad solution really.
It will be great when Unity makes classes like this public (another being most of the classes in Shuriken), because it hinders development and the functionality of games. Some of these areas of the engine are absolutely brilliant in theory, but without dynamic usability, there really isn't any point to them.
If there is a way that you can do this other than what is in those examples, it would be great if a mod could provide some input. But other than that, I'm afraid those are your only paths @BlackHorizonStudios.
Le sigh ...
That's a real let down, as we need this feature to be able to control wind for our storm system. Thanks for this, it pretty much sums it up. We'll have to take a different approach.
Answer by knowpixels · Feb 25, 2015 at 02:19 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.
Your answer
Follow this Question
Related Questions
Disable SCRIPT HELP!!!! 1 Answer
Script Not staying disabled 2 Answers
Turn Off/on culling mask by script? 2 Answers
disable/enable mouselook not working? 1 Answer
Re Enable C# script on camera 1 Answer