Uncategorized

Watch the Unity keynote

The Unite 2014 keynote was yesterday. There’s lots of exciting stuff coming for Unity (I’ll cover that in another post), but you can watch for yourself:

Some highlights

  • IL2CPP turns your C# bytecode into C++ code and compiles it, and is as fast as native C++
  • The new UI slated for Unity 4.6 is in open beta, and will be an open-source component hosted on Bitbucket
  • Unity 5’s GI (Global Illumination) and physically-based shaders look very impressive
Uncategorized

Go Support Kenney Land

Are you familiar with Kenney? If you check out his Open Game Art profile, you’ll see that he does awesome work, and makes a lot of it CC0/public domain, so that anyone can use it for their projects.

Well, he just started an IndieGoGo campaign to fund a space in the Netherlands called “Kenney Land,” for game developers to work, learn, and play. The campaign closes on 18 October, so you should check it out while you have the chance! If that idea alone is not reason enough to throw your money at him, backers at the $20+ level get a brand new 2D asset pack, including reworks and expansions for some of his previous work, a 2100+ asset “Roguelike pack,” and a bunch of audio clips and tracks.

What are you waiting for? Go!

Uncategorized

Anatomy of a Unity script

Here’s an example of the default script that Unity will create when you ask for a new C# script:

Most of this makes sense, but I’ve found myself wondering, “why would they include System.Collections, but not System.Collections.Generic?” There aren’t very many cases where I’d rather use an array than a generic List. The other default import, UnityEngine, makes sense because it provides access to the Unity API, but I couldn’t figure out System.Collections.

I discovered the answer while reading through Catlike Coding‘s Unity tutorials (specifically, the tutorial on making fractals):

Move the two child creation lines to a new method named CreateChildren. This method needs to have IEnumerator as a return type, which exists in the System.Collections namespace. That’s why Unity includes it in their default script template and why I included it in the beginning as well.

CreateChildren in the script referenced is a coroutine[ref]See the Unity manual entry on Coroutines for more information[/ref], which provides our answer: Unity coroutines must have a return type of IEnumerator, which is found in the System.Collections namespace. As a core framework feature, it makes sense that the Unity team would choose to include this by default in the new scripts created by the editor.

Uncategorized

Unity3D mouse follow script

I wrote this script to have a GameObject follow the mouse cursor, converting mouse position to whatever coordinate space you need. I use it with viewport space to display grid coordinates next to the cursor with a GUIText component.

[code language=”csharp”]
using UnityEngine;

public class MouseFollow : MonoBehaviour
{
new public Camera camera;
public float zValue = 0;

public enum CoordinateSystem
{
World,
Screen,
Viewport
}
public CoordinateSystem convertTo;
new Transform transform;

void Awake()
{
transform = GetComponent<Transform>();
}

void Start()
{
if (camera == null)
{
camera = Camera.main;
}
}

void Update()
{
Vector3 converted = Input.mousePosition;

if (convertTo == CoordinateSystem.World)
{
converted = camera.ScreenToWorldPoint(converted);
} else if (convertTo == CoordinateSystem.Screen)
{
// Input.mousePosition is already in screen space
} else if (convertTo == CoordinateSystem.Viewport)
{
converted = camera.ScreenToViewportPoint(converted);
}

converted.z = zValue;
transform.position = converted;
}
}
[/code]