Browsing Tag

unity5

Add Functionality to Button or Call Function with Button in Unity 5

With all of the changes to how Unity operates with even basics like Buttons, its easy to read deprecated information that just won’t work in your new Unity 5 (5.5 or 5.6+) projects. It really seems like the major wave of changes started occurring around 4.7, and what happened to how we used to make “buttons” with OnClick() functions or whatever.

However, even now, I still see a lot of misinformation that does actually work, but its the wrong way to do it, and can only lead to confusion or problematic behavior down the road. It is surprisingly easy to do button functionality, and I’ll try to explain each part as I go so you understand the mechanics behind what’s going on.

So we’ll roll with a simple and easy example, doing a step-by-step on how to make make a proper quit button.

1. We’ll be creating a script to attach the button.

2. Then we’ll be adding a call to a function in this script, using the built-in OnClick() list in the inspector.

UI Image Wont Stretch Problem in Unity 5

There’s a common problem that those new to the basic UI system in Unity have when it comes to properly stretching Images or Raw Images across the screen inside the Canvas. This can also happen even with other UI objects like the Panels. While the stretch functionality under Rect Transform in the Inspector is one the absolute greatest things in the UI toolset, it does unfortunately suffer from some un-intuitiveness.

The reason that probably led you here is that you’ve used the stretch mechanism before, perhaps many times before, but for some reason its just not working this time and its driving you crazy, right? Never fear!

Implementing Multiple Canvas Groups in Unity 5

 

There is often confusion about how to implement canvas groups in Unity 5. The documentation makes it fairly plain what canvas groups are, but doesn’t help so much on just how to use them. This confusion leads to people asking about creating multiple canvases (which is actually possible to do in Unity 5+).

The multiple canvas solution is simply the wrong way to go about implementing multiple canvas groups however. It shows a lack of understanding on how you can use this UI feature. Now, I do want to make it clear that I’ve noted others (including myself) managing to use multiple canvases (lightly) in a scene, without any seemingly majot detriment to performance. This is keeping in mind that performance is basically the primary reason touted as to why its best sticking to a single Canvas in a scene (the other reason being organization).

So, there are reasons (not relating to Canvas Groups) as to why you’d want to use multiple canvases, but I won’t be covering that here this time.