object fade OUT

how can i get an object to fade out after it has don some thing like expload and the objects from the exploaion are left there i would like them to fade out so it do not slow my pc. sorry for my spelling.

help plez

Use “renderer.material.color.a” then scale it to 0 over time, then just ensure you use a transparent shader + delete it a few seconds after it’s invisible using Destroy(gameObject).

30 minutes after posting is probably a little early to bump :slight_smile:

Do you have spell-check available? That would probably help you catch most of your errors.

As for your question, fading in and out is usually done by using alpha blending.

First, you have to use a shader that supports alpha blending (there are several of these among the built-in shaders; check out the particle and transparent shaders in particular).

Then, you have to modify the alpha value dynamically. This can be done by changing the alpha value of a color associated with the shader, or by modifying vertex colors (which requires that the shader support vertex colors as well).

If the shader has a parameter named ‘_Color’ (which some of the built-in ones do), you can modify the color via the Material.color property. If the color isn’t named ‘_Color’, you can modify it via the Material function that allows you to specify a color name.

To acquire a copy of the material that you can manipulate, use the Renderer.material property. (There are some subtle gotchas involved in instancing materials like this, but that’s probably not something you need to worry about at this point.)

do eny of you have at script or can tell me were i can find one

I’m sure there are some relevant scripts floating around on the forums or on the Wiki (maybe someone will post a link or two).

However, piecing things together from scripts other people have written (and that you may or may not fully understand yourself) isn’t a very effective way of doing things, IMO. I know it can be frustrating because you want results now and this stuff takes time to learn, but the fact is that technical disciplines like programming and game development require a certain amount of discipline and patience.

A good first step though would be to create a material that uses an alpha-blended shader with a _Color property (e.g. a shader from the ‘transparent’ category), and assign it to your object. Then, create a script that does nothing more than this (adjusted as needed for programming language):

renderer.material.color.a = .5;

And see if that makes your object translucent.

Once you’ve done that, you’ll be well on your way to making an object fade out.

so the code you gave me will not fade my object with out more info in the script. right.

like it will need time it takes to fade in or out. is that. correct

i will try to finish it my self but can you give me a exp.

Use Lerp;

// Converts a white color to a black one through time.
var lerpedColor : Color = Color.white;
function Update() {
    lerpedColor = Color.Lerp(Color.white, Color.black, Time.time);
}

This is from the scripting reference

Unfortunately, the documentation is misleading here in that although using Time.time does serve as an example, there are very few cases where you’d actually want to use Time.time as the interpolation parameter. (The use of Time.time in the example for Lerp() has caused a lot of confusion, judging from how often this comes up on the forums and on Unity Answers.)

True, Jesse. They should really give more real world examples in the docs. It would save a lot of headaches and a lot of posts on the forums. Or at least they could use Time.deltaTime so the timer starts when the function containing Lerp is called rather than from the start of the game.

That’s right.

Right, you’ll have to factor in time in one way or another (e.g. by using a coroutine or a timer of some sort).

For an example, try searching the forums and/or the Wiki for ‘fade’ or ‘fade out’; this is discussed fairly frequently, so I imagine you’d find some examples. (Or, maybe someone will post a complete example to this thread.)

fade or fade out on wiki is for a gui.

how do i factor in the time?

Wow, awesome answers to horrible questions.