- Home /
Show object for a specific platform only.
I want to have an EXIT button but only for Windows build.
How to do it? and I don't want to hide it, I want it to not to be rendered at all.
I would detect the platform using either preprocessor directives or Application.platform, and then activate/deactivate the button's gameobject accordingly.
But I may be missing something.... what's the difference in your $$anonymous$$d between hiding it and not rendering it?
I meant, it's best practice not to render an object for a platform that should not be visible too.
About activating the object. If I don't activate an object, would it still be in the RA$$anonymous$$?
Or objects that are not activate, are not loaded?
@nyonge you can respond too.
In short, yes, the object would still be in memory even if it's inactive, because it would've been loaded with the scene.
However, once it's loaded, if it's deactivated it'll have an incredibly small impact on your performance, so it likely wouldn't be an issue. Even loading would be $$anonymous$$iscule if it's just a simple button. You could have it deactivated by default, and only activate it if it's on Windows, which should work fine.
If you'd rather not load it at all, it cannot be in your scene at start. In that case, when you've detected that you're running Windows, you can use Resources.Load to add the object to your scene when necessary.
Answer by AmirSavand · Oct 27, 2017 at 04:18 PM
Best solution that takes the least RAM is to use Prefabs to add objects in the scene by platform condition.
Thanks to @nyonge and @Bonfire-Boy .
Answer by JonasAA · Oct 27, 2017 at 01:40 PM
#if (UNITY_STANDALONE_WIN)
// button logic
#endif
https://docs.unity3d.com/Manual/PlatformDependentCompilation.html
Answer by nyonge · Oct 27, 2017 at 01:43 PM
Platform-dependent compilation is your friend!
#if UNITY_STANDALONE_WIN
//do windows stuff
#elif UNITY_STANDALONE_OSX
//do apple osx stuff
#else
//do whatever else, presumably mobile or linux
#endif
Hope that helps :)
I know how to do it in code, but what about objects in editor?
I'd create a script called ShowWindowsOnly, with something like this
private void Start() {
#if UNITY_STANDALONE_WIN
//correct platform, do nothing
#elif UNITY_EDITOR
//show the button in the editor
#else
//it's another platform and not editor, disable object
gameObject.SetActive(false);
#endif
}
I'd do that too. can you read and respond the comments under my question? Thanks.
Your answer
