Enabled not working on Mac

Hey all, I’m currently developing on Windows, then checking in the project to our version control software to build on a Mac to deploy to iPad. A big problem I’ve got at the moment is that my .enabled function isn’t working on Mac whilst it’s perfectly fine on Windows… can anyone explain why this is?

What I need to do is have a few variables that I can slot scripts in to on my game object, and then toggle those variables on/off to toggle the scripts in the slots on/off. Here’s what I’ve got in the code:

var riddleTextScript1 : Component;

riddleTextScript1.enabled = false; //Or true, whichever

If you look up Component in the Unity Documentation, you might be surprised to find that ‘enabled’ isn’t even a member! The reason for this is that some components can be disabled, and others can’t- which means that having ‘enabled’ be a member of the Component superclass could be a problem for components such as ‘Transform’ which cannot be disabled (and as such the ‘enabled’ boolean wouldn’t make any sense).

The reason it was working for you on Windows is probably either that you were using a different version of Unity, or (as I think is more likely) the Javascript implementation there is a little more lax about this stuff. It’s about this time that I usually complain about Javascript’s fuzzy syntax, but at this point I think you know enough about that already.

The iPhone JavaScript compiler is very strict, and won’t allow you to do this. Implicit downcasting is pretty dangerous as it is, and so it simply won’t let you use ‘enabled’ when it can’t know for sure that all objects which inherit from Component will even have that member.

If the script in question is a MonoBehaviour (i.e any script you write), you can use

var riddeTextScript1 : MonoBehaviour;

Which does have an ‘enabled’ member, and can be used in this way.

Enabling and disabling scripts is a little bit more complicated then that, but you had the right idea!!!!!!!!!!!

All you would have to do is something like the code below:...

GetComponent(scriptNameHere).enabled = false;

This would disable a script that is attached to the same Game Object...

To disable a script on another Game Object, you would just do something like this:

GameObject.Find("gameObjectNameHere").GetComponent(scriptNameHere).enabled = false;

Just replace `gameObjectNameHere` with the name of the other game object with the script that you are disabling!!!! And once again, add in the name of the script!

And then obviously you can just change `.enabled = false` to true depending on what you're doing!!!! :)

You can also use tags to find the game object if you wish!

Also, I haven't tested these yet, so no 100% guarantees, but it should work!!!!

Here is the script reference for: `GameObject.GetComponent` http://unity3d.com/support/documentation/ScriptReference/GameObject.GetComponent.html if you wish

Hope this helps and feel free to comment back if you have any issues!