Playing With Lighting Effects In Unity 2D

Playing With Lighting Effects In Unity 2D

Adding the final bit of polish to my Flappy Jetroid game and wasn’t happy with the lighting when you die. Since it was nested inside of the player it just disappears when you die. Next I played around with the following code, which will put the light at the same coordinates but on the root of the hierarchy: GameObject light = GameObject.Find("PointLight") as GameObject; light.transform.parent = null;GameObject light = GameObject.Find("PointLight") as GameObject; light.transform.parent = null; Here what that looks like when the light is persistent after the player dies: While it’s much better it’s still not perfect. So I created this little script to fade down the light: using UnityEngine; using System.Collections;   public class FadeDownLight : MonoBehaviour {   private float start; private float end; private float t = 0.0f;   void Start () {   start = light.intensity;   end = light.intensity/5; }   void Update () { t += Time.deltaTime; light.intensity = Mathf.Lerp (start, end, t / 2); } }using UnityEngine; using System.Collections; public class FadeDownLight : MonoBehaviour { private float start; private float end; private float t = 0.0f; void Start () { start = light.intensity; end = light.intensity/5; } void Update () { t += Time.deltaTime; light.intensity = Mathf.Lerp (start, end, t / 2); } } And I modified the previous code to apply it dynamically: GameObject light = GameObject.Find("PointLight") as GameObject; light.transform.parent = null; light.gameObject.AddComponent("FadeDownLight");GameObject light = GameObject.Find("PointLight") as GameObject; light.transform.parent = null; light.gameObject.AddComponent("FadeDownLight"); Here is what the final results look like: As you can see there is now a nice subtle fade down and it’s less jarring. While you may be thinking...
Controlling Individual Particles In A Unity Particle System

Controlling Individual Particles In A Unity Particle System

Was playing around with how to get access to the individual particles active in a particle system. I am using one to create some dust in my game and when you die I want to have them stop moving and fall. Here is what the effect looks like: While I don’t think I am going to use this in the final game I thought I would share the code I used to make it happen. It wasn’t as straightforward as I had hoped to get access to each particle instance. ParticleSystem.Particle []ParticleList = new ParticleSystem.Particle[dust.particleCount]; dust.GetParticles(ParticleList);   for(int i = 0; i < ParticleList.Length; ++i) { ParticleList[i].velocity = new Vector3(0,.1f,0); }   dust.SetParticles(ParticleList, dust.particleCount); dust.gravityModifier = 1;ParticleSystem.Particle []ParticleList = new ParticleSystem.Particle[dust.particleCount]; dust.GetParticles(ParticleList); for(int i = 0; i < ParticleList.Length; ++i) { ParticleList[i].velocity = new Vector3(0,.1f,0); } dust.SetParticles(ParticleList, dust.particleCount); dust.gravityModifier = 1; Hope you can find a better use for it than I...
Flappy Jetroid Start Screen Title And Dust Particles

Flappy Jetroid Start Screen Title And Dust Particles

I spent some time on my flight home yesterday creating a proper start screen title as well as some additional elements to help polish the game up. Here you can see the new title, using the same font, Radio Space (http://www.dafont.com/radio-space.font): I also started adding in some final effects like dust particles to give the space a little more depth: I’ll be demoing off the game next week at the New York Game Forum on Fire...
Creating Clean Looking Icons In Unity For Mobile

Creating Clean Looking Icons In Unity For Mobile

Here is the basic workflow for how I create all the icon sizes I need for my cross platform Unity games. I start by creating the main icon in PhotoShop, or wherever, at 152×152. Here is the new icon graphic for Flappy Jetroid: Once I have this in PhotoShop I can use Save For Web to generate each different size: Since my icons are all pixel art I can just change the size and use Nearest Neighbor scaling. If you are not doing pixel art you can choose a different quality but I highly suggest generating out all the sizes you need by hand so they look clean. I’ve seen unity create blurry icons before if you don’t manually set each one up. If Unity does the resize it will probably look blurry on lower resolutions. Once I have all my icons I keep them in my Assets/Artwork/Icons folder: From there you just open up the platform settings and manually drag them over: Make sure you check Override for [PLATFORM X] so you can manually add the resized images you created. Going to keep sorting out all the icons I need for each platform. My Flappy Jetroid game is turning out to be the perfect cross platform...
Creating A Simple Unity Object Pooling Class for Flappy Jetroid

Creating A Simple Unity Object Pooling Class for Flappy Jetroid

Taking a quick break to go back and clean up the code in my Flappy Bird clone, Flappy Jetroid. I was seeing some minor performance issues on mobile, especially when creating all exploding body parts on the fly so I implemented a simple C# object pooling class in Unity. using UnityEngine; using System.Collections; using System.Collections.Generic;   public class ObjectPool : MonoBehaviour {   public int poolSize = 5; public GameObject[] instances; public bool prePopulate;   private List<gameobject> poolInstances = new List</gameobject><gameobject> ();   void Start () { if (prePopulate) PrePolpulate (); }   public void PrePolpulate(){ for (var i = 0; i < poolSize; i++){ var clone = CreateInstance(); clone.SetActive(false); clone.transform.parent = transform; } }   public GameObject NextObject(){   foreach (var instance in poolInstances) { if(instance.activeSelf != true){ return instance; } }   return CreateInstance (); }   private GameObject CreateInstance(){ var clone = Instantiate (instances [Random.Range (0, instances.Length)], Vector2.zero, Quaternion.identity) as GameObject; poolInstances.Add (clone); return clone; }   }using UnityEngine; using System.Collections; using System.Collections.Generic; public class ObjectPool : MonoBehaviour { public int poolSize = 5; public GameObject[] instances; public bool prePopulate; private List<gameobject> poolInstances = new List</gameobject><gameobject> (); void Start () { if (prePopulate) PrePolpulate (); } public void PrePolpulate(){ for (var i = 0; i < poolSize; i++){ var clone = CreateInstance(); clone.SetActive(false); clone.transform.parent = transform; } } public GameObject NextObject(){ foreach (var instance in poolInstances) { if(instance.activeSelf != true){ return instance; } } return CreateInstance (); } private GameObject CreateInstance(){ var clone = Instantiate (instances [Random.Range (0, instances.Length)], Vector2.zero, Quaternion.identity) as GameObject; poolInstances.Add (clone); return clone; } } Here is an example of how I...
Detaching Orphaned Ship Parts

Detaching Orphaned Ship Parts

One more little experiment. Now that I have everything wired up correctly, it’s really easy to use my previous detach part method to give each orphaned ship part a little effect as it breaks away from the main ship body. Just going through everything now and simplifying all my code so it’s cleaner and I can add these little kinds of details in as I get bored of doing the hard...

Subscribe To My Mailing List

Want to learn how to make a game? Not sure where to start? Even if you are a seasoned game maker there is still a lot you can learn from my mailing list. I'll be covering tips and tricks for how to build, release and market games each month.

Simply sign up for my mailing list and also get access to a 50% off discount code for my eBooks and other content. I promise to not spam your inbox!

Join Now