fade in out (again...sorry)

what I’m i doing wrong here, it’s late i need to get this done and i can’t see or think straight anymore…:???:

shader :

Shader "Tinted Alpha Blend" { 

Properties {
    _Color ("Tint (A = Opacity)", Color) = (1,1,1,1) 
    _MainTex ("Texture (A = Transparency)", 2D) = "" 
} 

SubShader {
    Tags {Queue = Transparent}
    ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha

    Pass { 
        SetTexture[_MainTex] {
            ConstantColor [_Color]
            Combine texture * constant
        } 
    } 
}

}

controlScript:

using UnityEngine;
using System.Collections;

public class FadeInAlpha : MonoBehaviour {
	
	public float delay;
	public Material[] mat;
	bool fade;
	
	IEnumerator Start () {
		yield return new WaitForSeconds (delay);
			fade=true;
	}

	void Update () {
		if(fade==true){
            Color color = renderer.material.color;
            color.a += 0.1f;
            renderer.material.color = color;
		}
	}
}

sorry this is quite simple and has been discussed many times, but i can’t seem to fix it with any googling…

anyway thanks to anyone taking the time to have a fresh look

That won’t work because it’s framerate-dependent; you can’t just add 0.1 every frame (well, you can, but it’s really not what you want). http://unifycommunity.com/wiki/index.php?title=Fade

–Eric

hey Eric thanks
i do get the follow errors I can’t seem to get solved… :frowning:

Assets/Standard Assets/Scripts/FadeInAlpha.cs(14,32): error CS0103: The name Fade' does not exist in the current context Assets/Standard Assets/Scripts/FadeInAlpha.cs(14,17): error CS1502: The best overloaded method match for UnityEngine.MonoBehaviour.StartCoroutine(System.Collections.IEnumerator)’ has some invalid arguments
Assets/Standard Assets/Scripts/FadeInAlpha.cs(14,17): error CS1503: Argument #1' cannot convert object’ expression to type `System.Collections.IEnumerator’

this Fade script is in Standard Assets/Scripts and on an empty GO in the scene.

this is the code i use to call the fading:

using UnityEngine;
using System.Collections;

public class FadeInAlpha : MonoBehaviour {
	
	public float delay;
	public float speed;
	public Material[] mat;
	//bool fade;
	
	IEnumerator Start () {
		yield return new WaitForSeconds (delay);
		//fade=true;
		StartCoroutine(Fade.use.Alpha(renderer.mat, 0.0f, 1.0f, speed, EaseType.In));
	}

	/*void Update () {
		if(fade==true){
            Color color = renderer.material.color;
            color.a += 0.1f;
            renderer.material.color = color;
		}
	}*/
}

You have to remove your script from Standard Assets. See Script Compilation Order.

–Eric

ok thanks all erros are gone except this one

almost there, how do i Fade in the object if it has multiple materials? renderer.materials gives this Error: object is a UnityEngine.Material[ ]. It must be a GUITexture or a Material
UnityEngine.Debug:LogError(Object)

ah and which shader do you recommend using?

You’d have to change the code in Fade to handle an array of materials. Any shader which supports transparency is fine.

–Eric

ah ok this does the trick, thanks for the script and help :wink:

using UnityEngine;
using System.Collections;

public class FadeInAlpha : MonoBehaviour {
	
	public float delay;
	public float speed;
	
	IEnumerator Start () {
		yield return new WaitForSeconds (delay);

		StartCoroutine(Fade.use.Alpha(renderer.materials[0], 0.0f, 1.0f, speed, EaseType.In));
		StartCoroutine(Fade.use.Alpha(renderer.materials[1], 0.0f, 1.0f, speed, EaseType.In));
		
	}

}

also the transparent/diffuse works fine as long as the alpha channel is white in the texture, not black :slight_smile: