Popular posts from this blog

WARNING: This post is long. I wrote this because I could not find an unbiased comparison of the modern N-Trig and Wacom technologies online. It was written in response to the artistic outcry regarding the Surface Pro 3. If you are an artist, I believe it is worth reading.

UPDATED as of 20th June 2014 to reflect N-Trig software advancements.UPDATED as of 23rd June 2014 to reflect new direct Digitizer comparison information.

Those of you who may visit this site regularly will know that I am a game developer, but what you might not know is that I also do a lot of sketching. (Maybe one day I will post the stuff online)

Since I am a geek, I do almost all of my sketching digitally, which means I am always looking out for new developments in digitizer technology. This brings me to this post in particular:

Following the announcement of the Surface Pro 3, many artists were shocked and disappointed by the news that the SP3 would be using N-Trig technology rather than Wacom technology like the SP…

TL;DR: You don't need to duplicate a bunch of code to do the same things to a Image and a SpriteRenderer, or RectTransform and Transform, etc. You can use a simple pattern called the Adapter Pattern. If you've never used it before, this post explains how.

The Problem: Image vs SpriteRenderer
Lets say you want to make a sprite fade out, maybe its a dead monster or a collectible, but in either case you want it to gracefully depart from the screen rather than blink out of existence. Kinda like this eyeball monster from Beastly:

So that's pretty easy right, one way of doing it is with a MonoBehaviour that modifies the sprites alpha value via SpriteRenderer.color. Your class might look something like this: public class AlphaFaderSprite : MonoBehaviour {
public SpriteRenderer spr;
public float fade_percentage;
void Update() {
spr.color = new Color(spr.color.r, spr.color.g, spr.color.b,
fade_percentage);
}
}
Now, anyone who's used Unity for more than an …