Unity3D Great Code Snippets

Unity3D Great Code Snippets

Why can’t you type these in for us?

I could totally type these in for you but I choose not to because I don’t want to and because there is inherent brain/learning value in typing them in yourself and I believe you will get more value out of this page if you type them yourself.  I type them in again every time I use them.  Start typing or find the answers somewhere else.

How to do something periodically

The easiest way to do this is with “InvokeRepeating”.  The second easiest way is with a coroutine.  But if you want to do it with code in the update method:

How to do things periodically
How to do things periodically

How to Drag an object with the mouse

How to Drag an Object with the Mouse
How to Drag an Object with the Mouse

How to quit your application

How to quit your application
How to quit your application

How to affect a bunch of GameObjects at once

How to delete a bunch of GameObjects at once
How to delete a bunch of GameObjects at once

How to do Collision Detection

How to do Collision Detection
How to do Collision Detection

How to add a menu item to Unity

How to Add a Menu Item in Unity
How to Add a Menu Item in Unity

Cycling through an array the easy way

This is how to set an object to a different texture every time you press the space bar.

Its elegant in its simplicity

Cycling through textures with mod
Cycling through textures with mod

 

Leave a Reply

Your email address will not be published. Required fields are marked *