Unity TrailRenderer Issue

Still developing my new game. Not much to report as I’ve spent most the time doing the tedious bits, like the menu system and save/load stuff, while still coming up with new “obstacles” for the actual game. One particular obstacle is going to be a portal type transporter. When my player (a ball in this particular case) hits the portal it teleports to another part of the scene. At present the player has a trail following it around and I didn’t want this to show during the transition from one part of the scene to the other. Easy, right?

collision.GetComponent<TrailRenderer>().enabled = false;

No compiler errors, no warnings. Everything seems fine. It just doesn’t work… eh? The only other alternative I dug up during a lengthy Google search was to set the time of the TrailRenderer to 0, then set it back to 1 after the transition. Credit to wijesijp for pointing me in the right direction (time) with his post on Unity Answers.

collision.GetComponent<TrailRenderer>().time = 0;

Doesn’t seem ideal but it gets the job done.

Hope this helps someone. At the very least it’ll be a future reminder to myself 😉
Cheers, J

New Game

I decided to have a short break from game making after my last attempt. I wanted to spend time thinking of a puzzle type game (that I think would appeal to more people than a simple endless shooter), plus learn how to release the game on both Android and iOS. I’ve managed to purchase a cheap iPhone 5s and a generous friend has lent me his Mac Book Air. Which is a great help as I really didn’t like the idea of investing so much on just my second game.

So far I’ve decided to make a game loosely based on pinball, but with (hopefully) less luck involved. At the moment I’m still in the test phase. I really need to be sure that the physics in Unity are the same across all platforms and that the game is fun.

Cheers, J

Finally released my first game :-)

Actually I released it last week but didn’t get around to posting the news here. So far it’s not had many downloads (just 9) so I’ll need to find better ways to market the game. TBF it’s mostly been a learning exercise so I don’t mind (too much) if it isn’t seen or received too well by players. It is, after all, a very simple endless shooter. Below is the gameplay video that can be seen on the Play Store.

If any readers would like to give it a go, here is the link to the download on the Play Store. C & C’s are welcome (either here or on the store page itself).

Overall I’ve enjoyed the experience of putting my first game together. Learning about Unity, Blender, C#, procedural generation, etc. Plus all the other knowledge required to actually publish. Now to think of a new project 🙂

Cheers, J

Posting to Facebook from an app

I figured this might come in handy for others out there as it took me a while to sort out the various bugs (mostly because I skimmed the documentation).

What I wanted to achieve was the ability for a game player to post his/her score to their timeline. Although it took me a while to figure out it’s really not as hard as some other blogs/forums make out. First download the Facebook plugin from the Unity Asset Store and import it into your game.

One gotcha that didn’t seem to get mentioned was the necessity to include a “using System;”. This ensures the Uri identifier is recognized. The following code is all that is necessary (some may be specific to my app but I’m sure you’ll get the idea).

using System;
using UnityEngine;
using UnityEngine.UI;
using Facebook.Unity;

public class Facebook : MonoBehaviour {
    void Awake() {
        if (!FB.IsInitialized) {
            // Initialize the Facebook SDK
            FB.Init(InitCallback, OnHideUnity);
        }
        else {
            // Already initialized, signal an app activation App Event
            FB.ActivateApp();
        }
    }

    private void InitCallback() {
        if (FB.IsInitialized) {
            // Signal an app activation App Event
            FB.ActivateApp();
            // Continue with Facebook SDK
            // ...
        }
        else {
            Debug.Log("Failed to Initialize the Facebook SDK");
        }
    }

    private void OnHideUnity(bool isGameShown) {
        if (!isGameShown) {
            // Pause the game - we will need to hide
            Time.timeScale = 0;
        }
        else {
            // Resume the game - we're getting focus again
            Time.timeScale = 1;
        }
    }

    public void ButtonFacebook() {
        FB.ShareLink(
            contentURL: new Uri("PUT LINK TO THE PAGE/STORE PAGE YOU WISH TO LINK TO"),
            contentTitle: "TITLE",
            contentDescription: "DESCRIPTION",
            photoURL: new Uri("LINK TO A PICTURE"),
            callback: ShareCallback
        );
    }

    private void ShareCallback(IShareResult result) {
        if (result.Cancelled || !String.IsNullOrEmpty(result.Error)) {
            Debug.Log("ShareLink Error: " + result.Error);
        }
        else if (!String.IsNullOrEmpty(result.PostId)) {
            // Print post identifier of the shared content
            Debug.Log(result.PostId);
        }
        else {
            // Share succeeded without postID
            Debug.Log("ShareLink success!");
        }
    }
}

After that create a button in your scene and point it to ButtonFaceBook() method.

Hope that helps someone.
Cheers, J