How to make a bubble in ten days…hum, minutes


I made a script to create bubbles in Unity.  This is actually my first script ever, so please be merciful! 😉

Just drag the script on any Sphere (or any object, for the matter), and it will do what is does.  I didn’t figure out yet how to change the bubble’s thickness and make it visible, so I used a color code.  Just shift between red (thinner) and blue (thicker) by pressing Alt or Command (or vice-versa).  Use space to make the bubble grow.

This is just for early prototyping and some of the bubble’s functionalites are still absent.  Of course, the main issue will be to incorporate voice, but its actual components are already there (duration = pressing spacebar, pitch = thickness, volume = growthSpeed)

If you want to play with the bubbles, you can drag the Rigid Body and Drag Rigibody components on top of it, but don’t forget tu uncheck Use gravity.

You’ll also see that I’ve started coding the bubble’s reaction with its environment, in this case, a wall, so you can add a wall to the scene and give it a WallProperties script including a pop boleean variable to make your bubble explode!

Anyway, I would love to see what the real programmers think of this!

PS : sorry for the messy indentation, WordPress doesn’t seem to like code-pasting…

var growthSpeed : float = 0.1;

var lifespan : float = 5;
var lifespanSpeed : float = 0.1;
var maxSize : float = 10;
var thickness : Material;
private var grow : float = 1;
private var canGrow : boolean = true;
private var created : boolean = false;

function Start () {

thickness = renderer.material;

function Update () {

if(thickness.color ==;
maxSize = 6;

if(Input.GetButton(“Jump”) && canGrow) {
transform.localScale=Vector3(grow, grow, grow);

if(Input.GetButtonUp(“Jump”) && canGrow){

if(Input.GetButtonDown(“Fire1”) && canGrow)

if(Input.GetButtonDown(“Fire2”) && canGrow)


if(grow>=maxSize || lifespan<=0)

function OnCollisionEnter(collision : Collision){
var wall = collision.gameObject.GetComponent(WallProperties);

                 if (wall.pop)

Leave a Reply