- Home /
Just a "write a script for me" question.
Create Fading Sprite in C#
I'm trying to create the conditions in which my main character (I call Jinbei) when it hit the shuriken, Jinbei will fade out. After a few milliseconds, Jinbei will fade in. How do I do that? I hope someone can make a script to make it in C#. Thank you
http://docs.unity3d.com/Documentation/ScriptReference/index.html
Vector3.Distance or OnCollisionEnter or OnTriggerEnter
Renderer.material
StartCoroutine or Time.time
I'm so sorry. I just feel confused to get a solution. I thought here I could just ask a help like a script. Sorry
This question should have beed rejected due to our $$anonymous$$oderation Guidelines.
ps: i don't think Luffy would ask such a question. He would send Usopp to figure it out :P
Answer by deltamish · Apr 16, 2013 at 03:37 PM
To create a fading out and in effect try using this script
//ommitted using unity engine and other
public class Fader : MonoBehaviour
{
public GameObject Sprite;///the sprite (most of the time most of the people use plane for sprite)
public float fadespeed = 2;
public GUITexture Spriteb;//if u are using this for sprite
void Update()
{
//if hit with particles
if(Sprite)
{
Sprite.renderer.material.color.a = Mathf.Lerp(Sprite.renderer.material.color.a,0,Time.deltaTime * fadespeed);
if(Sprite.renderer.material.color.a==0)
{
FadeIn();
}
}
if(Spriteb)
{
Spriteb.color.a = Mathf.Lerp(Spriteb.color.a,0,Time.deltaTime * fadespeed);
if(Spriteb.color.a ==0)
{
FadeIn();
}
}
}
IEnumerator FadeIn()
{
yield WaitForSeconds(2);
if(Spriteb)
{
Spriteb.color.a = Mathf.Lerp(Spriteb.color.a,1,Time.deltaTime * fadespeed);
}
//if hit with particles
if(Sprite)
{
Sprite.renderer.material.color.a = Mathf.Lerp(Sprite.renderer.material.color.a,1,Time.deltaTime * fadespeed);
}
}
}
hi deltamish, thank you very much. This is very helpful
Thanks for your script, so helpful :) So how can I fade back ?
Hi.... @Dusker Studios
Did you just copy the code or rewrite it yourself.. ?
Follow this Question
Related Questions
Why isn't my script changing the sprite's transparency? 1 Answer
Custom shader of sprite results in black alpha. 0 Answers
Transparency When DistanceProblem 0 Answers
Can a sprite atlas be 4 bit? 0 Answers