Category Archives: Unity

Create 1 Frame Animations in Unity 3D

I was looking to make a 1 frame animation in Unity and wasn’t able to find a guide. In case anyone is curious, this is what I did:

When making a multi-frame animation, you can simply select all of the frames in a sprite and drag them to the prefab. This creates the animation for you. However, if you drag just one frame from the sprite, it will add it as a sprite renderer.

If you would like  a 1 frame animation from that sprite, right click the frame you want in the Unity Editor and click Create->Animation

Ta da! You’ve now got a 1 frame animation.

New UI Prefab Scaling Solution

I recently changed the settings on my UI Canvas from “Screen Space – Overlay” to “Screen Space – Camera”. Which is how I’m sure it was supposed to be done in the first place (n00b here).

Anyway, in doing so, all of my UI prefabs were coming in scaled to 53.3333%.

I did a quick hack using a script to set those back to 1, but I figured there must be an elegant solution.

I finally found the (so, so simple) solution in the Unity forums.

When instantiating a prefab into the UI, you need to add the “false” argument when setting the parent.

Use

GameObject obj = (GameObject)Instantiate (prefab);
obj.transform.SetParent (parent.transform, false);

 

NOT

GameObject obj = (GameObject)Instantiate (prefab);
obj.transform.SetParent (parent.transform);

Deleting Child Objects Recursively in Unity

It took me a bit of Binging to find a method that worked the way I needed.

1st, create a public GameObject to hold the parent of the items you are looking to delete. Set this either from the Unity Editor or in code.

Then simply call a foreach loop on the parent GameObject as below to delete all children.

foreach (Transform child in searchResultParent.transform)
{
     Destroy(child.gameObject);
}

SSL at Last

It’s long over due, but I finally got an SSL certificate for shernet.com! Was happy to find (sorry for the advertisement) a Comodo Wildcard SSL cert on SSL2Buy for only $60. Was afraid it might be too good to be true, but everything went great, including testing a certificate reissue.

Unity engine will finally connect to my web server without yelling at me about an bad certificate. What a happy day 🙂

To Unity and Beyond

It’s been a while since I got to sit down and write some code. There’s one project that’s been on my mind for years, but it’s languished for some time. I decided to give it another go, this time using Unity instead of HTML5.

Since this project is probably going to take quite a while, and I’m not really expecting much from it in a return on investment point of view, I’m using the free Unity. Free Unity, as you probably know, lacks .Net sockets for mobile platforms. Since I’d really like to get it working on iOS, and don’t have $3000 to spend on Unity Pro and iOS Pro, I’m going to stick with the old GET/POST method I started with back when I was using HTML5.

To communicate with my server then, I’ve been using the WWW class in Unity.
WWW www = new WWW ("http://server/function.php", pData, headers);

However, because WWW runs as an Enumerator and requires
yield return www
I was having all sorts of trouble getting the result from the WWW GET.

What seems to be working for was to put the WWW command in its own Unity C# script, use evil global variables, and run it by using:
gameObject.AddComponent("Login");

I’m still hoping to find a way to pass parameters to the added component, rather than using global variables, but I feels good to finally start passing some sanity checks!