Home | Rules and Guide | Sign In/Create Account | Write a Post | Reddit | #ludumdare on irc.afternet.org (Info)

Thanks for making Ludum Dare 26 AWESOME! See you in August!

Ludum Dare 26 — April 26-29th, 2013
[ Results: Top 100 Compo, Jam | Top 25 Categories | View My Entry ]
[ View All 2346 Games (Compo Only, Jam Only) | Warmup ]

[ 10 Sec Video Compilation (x3) | 260 Game Video Compilation | IndieCade Deal | Ludum Deals (Unity Deal Ends Soon!) ]


Unity3d ScreenEffects class

Posted by (twitter: @https://twitter.com/#!/oddgoo)
April 22nd, 2012 4:52 am

Greetings!

If  you are like me, and leaving the UI until the end, chances are you might find this useful, its a simple Singleton that will flash or fade in a texture. Its quite rough tho!

Here is the class:

 

//ScreenEffects.cs

using UnityEngine;
using System.Collections;

public class ScreenEffects : MonoBehaviour {

private static ScreenEffects m_Instance;

private static int curr_Effect;

private static float speed=1;

public static ScreenEffects Instance
{
get
{
if(m_Instance == null)
{
m_Instance = GameObject.FindObjectOfType(typeof(ScreenEffects)) as ScreenEffects;
if(m_Instance == null)
{
m_Instance = new GameObject(“ScreenEffectsObject”).AddComponent<ScreenEffects>();

}
}
return m_Instance;
}
}

private GameObject GUItextureObject;

void Awake () {
GUItextureObject = new GameObject(“GUItextureObject”);
GUItextureObject.AddComponent<GUITexture>();
}

public void FlashTexture (Texture textureToFlash,float Speed) {

speed=Speed;

curr_Effect=1;

GUItextureObject.guiTexture.texture=textureToFlash;

Color colorVar = GUItextureObject.guiTexture.color;
colorVar.a = 1f;
GUItextureObject.guiTexture.color = colorVar;

Rect inset = GUItextureObject.guiTexture.pixelInset;
inset.x=400;
inset.y=225;
inset.width=2000;
inset.height=2000;
GUItextureObject.guiTexture.pixelInset = inset;

}

public void FlashTextureMouse (Texture textureToFlash) {
curr_Effect=1;

GUItextureObject.guiTexture.texture=textureToFlash;

Color colorVar = GUItextureObject.guiTexture.color;
colorVar.a = 1f;
GUItextureObject.guiTexture.color = colorVar;

Rect inset = GUItextureObject.guiTexture.pixelInset;
inset.x=Input.mousePosition.x;
inset.y=Input.mousePosition.y;
GUItextureObject.guiTexture.pixelInset = inset;

}

public void FadeTextureIn (Texture textureToFlash,float Speed) {

speed=Speed;

curr_Effect=2;

GUItextureObject.guiTexture.texture=textureToFlash;

Color colorVar = GUItextureObject.guiTexture.color;
colorVar.a = 0f;
GUItextureObject.guiTexture.color = colorVar;

Rect inset = GUItextureObject.guiTexture.pixelInset;
inset.x=400;
inset.y=225;
inset.width=2000;
inset.height=2000;
GUItextureObject.guiTexture.pixelInset = inset;

}

void Update () {

if(curr_Effect==1)
{ if(GUItextureObject.guiTexture.color.a>0)
{
Color colorVar = GUItextureObject.guiTexture.color;
colorVar.a -= 0.01f*speed;
GUItextureObject.guiTexture.color = colorVar;
}
}
else if(curr_Effect==2)
{
if(GUItextureObject.guiTexture.color.a<1)
{Color colorVar = GUItextureObject.guiTexture.color;
colorVar.a += 0.01f*speed;
GUItextureObject.guiTexture.color = colorVar;
}
}

}
}

 

 

PD: Is there a way to insert code format in here?

 

 

 

 

Leave a Reply

You must be logged in to post a comment.


All posts, images, and comments are owned by their creators.

[cache: storing page]