How safe is using api keys in a script in Unity WEBGL - unity3d

I'm developing a project using WEBGL and I was wondering if it is safe to use a private key directly in the code.
Let's say that I have a private key called DB_KEYS.
I must use this private key in the source code.
When I deploy the game, are the users able to see the source code of my game and so the DB_KEYS variable?
Thank you in advance, have a nice day.

Related

Game Manager that controls two characters

I have a question.
I'm trying to make a runner game with 2 characters not one. I've done the movement and the camera related stuff.
Now I'm trying to add the Game Manager.
The problem is that my Game Manager isn't able to accesss the PlayerMotor of both characters.
I found a tutorial on Youtube that uses a singleton but it accesses only one player character which is obvious cause it's a singleton. So can you help me out guys? Unfortunately I'm not a programmer so I can't figure it out.
How can the Game Manager access both of their PlayerMotor instances to start the game?
From: Unity - Scripting API: Object.FindObjectsOfType
You can retrieve your Playermotor scripts by using FindObjectsOfType like that:
var playersMotor = Object.FindObjectsOfType<Playermotor>(); // find Playermotor scripts in your scene and store it in playersMotor
Or:
var playersMotor = Object.FindObjectsOfType(typeof(Playermotor));

Unity3D AssetDatabase.LoadAssetAtPath() vs Resource.Load()

My partner in game dev are looking at Unity. I dynamically loaded an asset using Resource.Load() and he used AssetDatabase.LoadAssetAtPath(). They both seem to work so which one should be used? Why have 2 different ways to dynamically load assets?
AssetDatabase.LoadAssetAtPath() vs Resource.Load() ...They both
seem to work so which one should be used?
None of them.
Your partner will end up with a game that he cannot build because he used AssetDatabase.LoadAssetAtPath(). The AssetDatabase.LoadAssetAtPath() function came from the UnityEditor namespace which is only used to make Editor plugins. It won't work outside the Editor and it won't even let you build your game at-all.
You using Resource.Load is fine but Resource.Load requires the use of the Resources folder which is known to cause slow down loading time of the game.
AssetBundles is the recommended way. You can put those files in the StreamingAssets folder then use the WWW or AssetBundle API to load it during run-time. You can learn more about how to use AssetBundles here

How do I feed Unity Web Player extern data?

I am new to using Unity3D, and I am supposed to use it on a web application (which is build with Ruby on Rails).
My problem is that I need to feed it data from my database but I don`t know how to give it extern data.
I`d appreciate any kind of help. :)
You can use WWW to make a request on the server and receive data.
http://docs.unity3d.com/ScriptReference/WWWForm.html (see the 2nd example)
Note that Unity Webplayer is no longer updated and its already removed from Unity 5.4 ( http://blogs.unity3d.com/2015/10/08/unity-web-player-roadmap/ )

Unity3d protect code

We have a code in a unity3d game that we wish to protect from decompilation(will be published in ios,android,webgl and unity plugin). How should we protect it? Should we write that part of code as unmanaged plugin(c++)?
It's not possible to release software that can't be reverse-engineered.
This is POSIBLE. Some packages have standart unity packager format. So.. If you use dynamic assets or if you use CodeContainers you need to protect your code.
So what you shoud do:
If you use dynamic assets packages: Make dll's from code or make one controller class.
If you use CodeConainers (JS) make main C# controller. After this you can extends classes or simply call methods.
PS: If you want to secure not code assets, you need make binary encoding. And when you load level or prefab you just decode this asset and use.
You could use obfuscation techniques, which allows you to protect your package from reverse engineering, but just from those, who is not VERY (i am talking about high-level reverse engineers, who could decompile your code and deal with ASM or could decompile your iOS/Android project) interested, in any case for Unity, iOS
You can obfuscate the your source code using the Remiix Obfuscator plugin in unity asset store.
It's free and easy to use and support many platform of build on unity(android, ios).

How can I get sensor data into Unity while using Google Cardboard?

I have the basic Google Cardboard Unity application loaded and working great.
I want to utilize a few sensors on my phone that aren't available in Unity. For example, I want to get access to the STEP_DETECTOR sensor.
I created my own UnityPlayerActivity, and without Cardboard, it seems to work well. My problem is that I have no idea how to use my custom UnityPlayerActivity WITH cardboard.
From what I can tell, the cardboard demo uses a "UnityCardboardActivity" class as the main activity. I took a look at UnityCardboardActivity.jar and it looks like the UnityCardboardActivity class inherits from CardboardActivity, NOT UnityActivity.
So my guess is that UnityCardboardActivity is manually starting the default UnityPlayerActivity somewhere in its code, but I can't change that to start my own custom UnityPlayerActivity in any way that I can tell.
Is there any way to get that sensor data without using a UnityPlayerActivity?
I tried making my activity extend UnityCardboardActivity instead, but for some reason I don't have access to the "getSystemService" method when do that, so I can't get access to any sensors.