Tag Archive for unity tutorial

Unity useful tips and tricks

Hello,

We have been using Unity for quite some time now and although its a fantastic piece of software for developing games, there are a number things that can hinder your development time. This post hopes to remedy this and help everyone who uses Unity; from beginner to advanced.

If you want to add colliders, but are annoyed by the 0.01 import scale this is a handy little bit of code

using UnityEditor;
public class FBXScaleFix : AssetPostprocessor
{
public void OnPreprocessModel()
        {

                ModelImporter modelImporter = (ModelImporter) assetImporter;                    
                modelImporter.globalScale = 1;        
                modelImporter.addCollider = true;
                modelImporter.normalImportMode = ModelImporterTangentSpaceMode.Calculate;
        }  
}

Naming Principles

  1. Use short names, and proper names. Call it what it is; a car would be Car.
  2. Choose names that are simple and can be spelt. Keep it simple
  3. Be consistent. This is for both naming convention and names.
  4. Do not use spaces, underscores, or hyphens if possible.
  5. Do not use abbreviations: InfantChild should NOT be infChild.
  6. Keep the most specific descriptor on the left: SelectButton, not SelectPaused. Its easier to find the word Select than searching the word button.
  7. At times when you have multiple items of the same name start at 0 not 1
  8. Use different words for different item types. Use Cup, Mug, Beaker instead of cup1, cup2 etc
  9. To find important items in the scene, use $ at the beginning of the name, so it always appear at the top of the scene hierarchy.
  10. It is good practice to name temporary objects with a double underscore __Bullet.

A god trick going around that maybe people have yet to hear is to use underscores between the core names. For example:

  • Texture: Chair_Diffuse and Chair_NormalMap
  • Skybox: TownSky_Top and TownSky_North

Other General Stuff

  1. Make sure function names are spelt correctly. They wont show an error.
  2. OnTriggerEnter and OnTriggerExit use COLLIDERS.
  3. OnCollisionEnter and OnCollisionExit use COLLIDERS.
  4. Put all pivots on the bottom of the prefab, this makes it easier to move around in the sceneview.
  5. On Creating a GuiTexture whilst having a 2D texture selected in the ‘project pane’ will automatically use that texture (instead of the default Unity Logo) and correctly set up the pixel inset values.
  6. Cameras in Unity can have their own skybox via adding the skybox component to any camera.
  7. Cubemaps are never compressed in vram (ARGB32) (standalone/web player), for skyboxes you are better off using 6 compressed textures if memory is an issue.
  8. Use [ ] around important gameObject names or append an underscore to the beginning to place them at the top of the hierarchy.
  9. Holding down “Ctrl” you can drag an object block at a time (like a snap feature).
  10. Select the camera in the hierarchy then GameObject -> Align With View. This will put the game camera at the location of the scene view cam
  11. Select the main camera then GameObject -> Align view to selected to move the scene camera to the position of the main camera
  12. Create a material with the shader you want to use highlighted in the project browser it will use the selected shader by default.
  13. FBX Scale & Automatically add colliders 🙂
  14. Delete inspector array items (like the input manager) by clicking on the item and pressing cmd/control & delete
  15. You can insert into inspector array items by selecting an item and hitting cmd/control & d to duplicate it.

 

For further information and tricks, check out JasperStocker