Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FadePlayableBehaviour.cs
using UnityEngine;
using UnityEngine.Playables;
public class FadePlayableBehaviour : PlayableBehaviour
{
public GameObject targetObject;
public bool IsFadeOut;
private Renderer[] renderers;
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
if (targetObject == null) {
return;
}
if(renderers == null)
{
renderers = targetObject.GetComponentsInChildren<Renderer>();
}
var currentTime = (float)playable.GetTime() / (float)playable.GetDuration();
for(int i=0; i<renderers.Length; i++)
{
var color = renderers[i].material.color;
color.a = IsFadeOut ? 1 - Mathf.Clamp01(currentTime) : Mathf.Clamp01(currentTime);
renderers[i].material.color = color;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment