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

This isn't a site to ask for scripts.

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

dnot feel sorry

This question should have beed rejected due to our [Moderation Guidelines][1]. ps: i don't think Luffy would ask such a question. He would send Usopp to figure it out :P [1]: http://answers.unity3d.com/page/modguide.html

1 Answer

1

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

i am glad the script helped you out

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.. ?

Yeah..I was an ameatur Idiot when i wrote that script.. I never looked back ever since.. Not even yesterday.. I am truly sorry if i had caused any problems.. I will write a new code and update it in next few days when i am free.. Thanks @Bunny83 for poiting out my mistakes and reminding me of it