Month: July 2015

  • Sound and music in Unity

    To add sound/music add the ‘Audio Source’ component to an object. Put your sound files in the ‘Resources’ folder ideally in it’s own folder called maybe ‘sounds’. You can drag a sound file into the ‘AudioClip’ area and tick ‘Play on Awake’ and ‘loop’ for background music. That’s all you need for basic background music.…

  • Screen Fader in Unity

    Basically this is big black box to fade in and out over everything else to transition between screens. First I made a UI Image that is the same width as the canvas and then stretched it’s height to fill the rest of the screen like so: gameObject.transform.localScale = new Vector2 (1,(float)Screen.height/(float)Screen.width); I add a “Canvas Group” component to the…

  • Demonfall Week 15 Progress

    The tutorial levels are done… I guess. I kept it simple and didn’t literally tell the player how to play the game except for the goal of the game. I did give hints in the form of flashing buttons indicting them to tap them. Hopefully it’s easy enough for the player to understand – only…

  • Wait for Real Seconds class using static function in Unity

    Paste this code into a new script called ‘CoroutineUtil’. using UnityEngine; using System.Collections; public static class CoroutineUtil {     public static IEnumerator WaitForRealSeconds(float time)     {         float start = Time.realtimeSinceStartup;         while (Time.realtimeSinceStartup < start + time)         {             yield return null;         }     } } What this class does is expand on the delaying code method by making it work even when the game is paused. The function is made static so that any other script can access…

  • Demonfall Week 14 Progress

    This week, I made the high scores work including star ratings as shown in the screenshot. I’ve also done the logic and visual cues for completing the tutorial levels. I’ve also updated the Demon Spirit tutorial level so it flows better and also so the only way to beat it is to understand the mechanics of…

  • Rotate and scale mixin

    @mixin rotate($deg,$ox:50%,$oy:50%){ -ms-transform: rotate($deg); /* IE 9 */     -ms-transform-origin: $ox $oy; /* IE 9 */     -webkit-transform: rotate($deg); /* Chrome, Safari, Opera */     -webkit-transform-origin: $ox $oy; /* Chrome, Safari, Opera */     transform: rotate($deg);     transform-origin: $ox $oy; } The default of the point of rotation is set…

  • Demonfall Week 13 Progress

    The little things from last week’s checklist are done. This week is all about the start menu and the screen shot is the section with the most content: the demon select screen. The screens are pretty much finished, it’s nothing flashy but gets the job done I think. I still have to link the high…

  • Loading JSON in Angular

    First we have our JSON file so like: [{     “name”: “Azurite”,     “price”: 2.95,     “canPurchase”: true }, {     “name”: “Bloodstone”,     “price”: 5.95,     “canPurchase”: true }, {     “name”: “Zircon”,     “price”: 3.95,     “canPurchase”: false }] To use it, instead of app.controller(‘basicController’, function(){     this.products = gems;   }); where…

  • Custom Directives in Angular

    What custom directives let you do is package a whole lot of functionality and display it in just 1 line. Here is an example of making a custom directive in the js: app.directive(“projectDescription”,function(){         return{             restrict:’E’,             templateUrl:’projectDescription.html’,             controller:function(){                 this.projects = projectsVar;…

  • Touches in Unity

    In this example, there is a left and right button that moves the character in that direction. Both buttons have a box collider. leftBox = GameObject.Find (“leftButton”).GetComponent<BoxCollider2D> (); rightBox = GameObject.Find (“rightButton”).GetComponent<BoxCollider2D> (); void Update () { foreach (var touch in Input.touches) {             if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled) {                 Vector2 wp = Camera.main.ScreenToWorldPoint (touch.position);                 Vector2 touchPos = new Vector2 (wp.x, wp.y);                         if (leftBox == Physics2D.OverlapPoint (touchPos)) {                         //do stuff                     }                     if (rightBox == Physics2D.OverlapPoint (touchPos)) {                         //do stuff                 }             }         } } Basically, we check each touch, convert it to world space and then check…