22

This answer relies heavily on Android's official documentation (the quoted parts, specifically). How to setup Multidex Support for Unity Project What is Multidex: Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable ...


12

Is there a noticable performance difference? No. There technically is a very small performance difference, but it is not significant enough to base your choice of language on in most cases. Is it possible to use libraries developed for one language while developing in the other one? Yes. As long as you make sure to keep the folder structure recommended by ...


11

Java is not supported by Unity. You should check out C#, however; it's a very similar language that takes a lot of influence from Java while arguably smoothing out some of the rougher edges of the language. It should also be noted that you will need both Unity Pro and Unity Android Pro in order to create Android games using Unity. As jhocking and ashes999 ...


11

Applying the RequireComponent decoration to a script will ensure that the GameObject has the specified component. If the component is missing: Unity will attempt to add a component of this type for you, If this fails (e.g. mixing RigidBody/RigidBody2D) then the script will refuse to attach. C# sample: [RequireComponent (typeof (Rigidbody))] public class ...


10

Have your gameobject hierarchy like so: STAR - FACE - BODY Then rotate the Body of the star. Your face and body will be two seperate entities of course, where the face will be drawn overtop the body gameobject. This keeps both gameobject independent from one another. EDIT Have your main script on the Star gameobject. Then attach the RigidBody to ...


8

The very first question all beginning Unity developers have is C# or JS. Always go with C#. Now, right now you may be thinking, "But I don't want to learn C# and I already know a bit of JavaScript." But the misleading thing you need to consider is that Unity JavaScript is not JavaScript. It is a superficial veneer of ECMA syntax over .NET CLR. It does not ...


7

First off, I would recommend C# over JavaScript for programming in Unity for two main reasons. The first reason comes down to the strong/weak typing difference that you kind of dismissed. I do think strong typing works better than weak typing on a conceptual level, but frankly that's a whole big argument people have and so I'll focus more on a specific ...


7

I'd like to separete these things due to clearity reasons but I wonder if calling different FixedUpdate() functions would imply some kind of issue. For example: is their execution ensured to be called sequentially or they could run asincronously? Each callback of each MonoBehaviour will be called exactly once for each update loop, but you haven't any ...


6

Instead of using a collider for your terrain, you can also use a plane to perform a raycast. For example, if your grid is situated on the XZ plane, you can do something like this: static Plane XZPlane = new Plane(Vector3.up, Vector3.zero); public static Vector3 GetMousePositionOnXZPlane() { float distance; Ray ray = Camera.main.ScreenPointToRay(...


6

You can compress certain assets individually. After building the project, go into the log file and there will be a summary of what assets were packaged with the apk, and their sizes. (On windows, located in C:/Users/username/AppData/Local/Unity/Editor/Editor.log) Find large textures/music/sound, and select them in the project view to bring them in the ...


6

You can use Time.TimeScale for slow motion effect.


6

Add a restriction to the tiles your A* algorithm is able to consider and this will eliminate the undesired diagonals. You wish to remove prevent two things from occurring, the first is you do not wish your algorithm to travel through walls and the second is that you do not wish the algorithm to travel along diagonals. Let us suppose your maze is ...


6

Color.Lerp in Unity works just as any lerp implementation, which works like this: float lerp(float a, float b, float t) { t = clamp01(t); return a + (b - a) * t; } Or with multiple components, like Color: Color lerp(Color a, Color b, float t) { t = clamp01(t); return new Color( a.r + (b.r - a.r) * t, a.g + (b.g - a.g) * t, ...


6

The issue in your code is that you only check for the key press in the OnTriggerEnter function, which only gets called when the collider enters the trigger. What you probably want to do instead is check for the keypress inside the OnTriggerStay function, which gets called while the collider lies inside the trigger.


5

You should add a game-object as a public member to your class. Let's assume you write a behavior for your Camera and name it CameraController. Here's how this could look like: using UnityEngine; using System.Collections; public class CameraController : MonoBehaviour { // this will turn up in the Inspector where you can assign // an object to ...


5

It is not possible to get the names of the PlayerPrefs keys at runtime. Instead you could opt for serializing your highscore table, and adding it as a string value to a fixed key in PlayerPrefs. This is untested C#, but you'll figure it out: // Load highscores. string highscoresSerialized = PlayerPrefs.GetString("highscores", ""); Dictionary<string,int&...


5

Well the totalShots value stays at 10 until you increase it, so totalShots % 10 == 0 will continue to be true until you increment totalShots the next time, so if you keep calling ShotCounter() it will increment the level. You need to only either call it only once, or add some other check into it. I suppose the easiest fix would be to call ShotCounter() ...


5

Found it! Attribute [ExecuteInEditMode] does what I want [ExecuteInEditMode] public class RandomRotation : MonoBehaviour { void Start () { #if UNITY_EDITOR this.transform.Rotate(0, MyRandom.Rotate(this.GetInstanceID()), 0); this.transform.localScale = MyRandom.Scale (this.GetInstanceID(), 0.4f, 1f); Debug.Log("Editor"); #else ...


5

The simplest, modestly realistic, model I can think of would be parameterized by the following: Mz The Turning Moment of the ship about the steering (ie Z or yaw) axis; L/2 The distance of the rudder from the turning axis, approximated as 1/2 the ship's length L; v The current linear velocity of the ship (relative to the water, not the land nearby, so ...


5

void ReverseGravity() { Physics2D.gravity = new Vector3(0, -1.0F, 0); } void ApplyGravity() { Physics2D.gravity = new Vector3(0, 1.0F, 0); } //if you are not using 2D then use Physics.gravity = new Vector3(0, 1.0F, 0); //you could also use Rigidbody AddForce to get your desired effect without changing any physics. //you can set up a bool ...


5

You can load a scene without destroying anything in the current scene by using the method SceneManager.LoadScene with the LoadSceneMode.Additive flag. Example: SceneManager.LoadScene ("MinigameSceneName", LoadSceneMode.Additive); That way all the objects from the loaded scene get added to your current scene. Both scenes now coexist with each other in the ...


5

Update Order When you’re keeping track of game logic and interactions, animations, camera positions, etc., there are a few different events you can use. The common pattern is to perform most tasks inside the Update function, but there are also other functions you can use. FixedUpdate: FixedUpdate is often called more frequently than Update. It can be ...


5

The label and goto in your FixedUpdate method is an infinite loop equivilent to: while(true) { Invoke("FoodSpawn", spawnTime); } Once the engine executes this method it would never leave it (and would keep queuing new Invokes). A better option may be using InvokeRepeating in the Start method as indicated in the documentation page.


5

Common approach Shuffle your array. A simple Fisher–Yates shuffle will do. The result is that you will have your array of GameObject in a random order. When picking a GameObject to activate, just pick the next one. To do that, you keep an int index field that tells you where you are so far, it starts at zero... then, on the event, you pick the GameOBject ...


4

Simple Answer Use a class to load the original prefab from Resources.Load(string prefabPath, typeof(GameObject)); Store this returned prefab into a resource pool class by path key. For instance: Dictionary<string, GameObject> prefabLookup; You can then grab the original prefab anytime you need it. Use a helper method to automatically load at ...


4

First (and I only say this because you are new to Unity), make sure you have the script attached to your Terrain GameObject (drag it from the project window and release it on top of the terrain GameObject in the Hierarchy). Then you can access the terrains transform in the script. Note that this will actually work for any GameObject including Prefabs, ...


4

Since QuantumCold_B is not defined as a variable, you won't be able to use it that way. If "QuantumCold_B" is the name of the object in the editor, you can use the GameObject.Find function to get the game object that has the name you want. So, you would use: var myObject : GameObject; // This will return the game object named Hand in the scene. myObject =...


4

Unity supports only C#, JavaScript and BooScript for scripting. However as Philipp mentioned, if you know Java then you know 90% of C#. I still know only Java and C++ and its easier for me to translate my logic into C# (Given that I didn't know much about C# even after coding for a year in Unity). You can however write plugins in Java for any native ...


4

Yes, it is possible to do using iterators. I've put some pseudo C# code here to give you an idea. You use yield return to return something from an iterator, which has the same behavior as yield in a theoretical coroutine. You can then store the iterators in a list, dictionary, or other structure to keep track of them, and run them all. Note that coroutines ...


4

You can use a RTT (render-to-texture) and a custom camera to one-shot render to it to merge all the layers using the GPU. You can then save and use the resulting texture. http://docs.unity3d.com/Manual/class-RenderTexture.html If your render texture has alpha then it will maintain the composited alpha values as long as you use the proper separate color-...


Only top voted, non community-wiki answers of a minimum length are eligible