appear/disappear gameobject

hi, i've created several gameobjects in my scene. now at runtime i want only a few to be shown at startup. later i'd like to have some gameobjects fade away and completely disappear, while others to appear fading in. how do i do that in a generic way, i. e. a function taking the object id as param? how do i tween material alpha using Ani.Mate generically? thanks, flexrails

To make them appear and dissappear (without fading) is very simple. Just enable or disable each game object's renderer component. Here's the example from the docs:

// make the object invisible
renderer.enabled = false;

// make the object visible
renderer.enabled = true;

// toggle object's visibility each second
function Update () {

    // Find out whether current second is odd or even
    var seconds : int = Time.time;
    var oddeven = (seconds % 2) == 0;

    // Enable renderer accordingly
    renderer.enabled = oddeven;

For fading individual game objects in and out, you'll need to use one of the shaders from the "Transparent" family, then adjust the alpha value of the main colour, for each gameobject's material.

Note that when you modify a game object's material using Renderer.material, you actually create a temporary clone of that material so that it is no longer shared with other gameobjects. This means you'll be able to fade gameobjects individually even though they may share the same material in the editor. Any clones that are made at runtime like this are cleaned up and re-set when you click stop.

that's what i ended up with for tweening alpha material using AniMate. hope it helps.

function TweenToAlpha(object:GameObject, duration:float, toAlpha:float) {
    var renderers = object.GetComponentsInChildren(Renderer);
    var materials:Array = [];
    for (var r in renderers) {
    	for (var m in r.materials) {

    for (var m in materials) {
    	Ani.Mate.To(m, duration, {"colorName": "_Color", "a": toAlpha});	
    yield WaitForSeconds(duration);

For switching between multiple game objects look also at the answers provided to this question: