Created
February 13, 2018 09:53
-
-
Save PopupAsylumUK/bc37a3d8d02f9a5c274637e503743c21 to your computer and use it in GitHub Desktop.
Plays an animation on an Animator automatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Animations; | |
using UnityEngine.Playables; | |
public class PlayAutomatically : MonoBehaviour { | |
[SerializeField] | |
AnimationClip modelAnimationClip; | |
PlayableGraph playableGraph; | |
float playableGraphTime; | |
[SerializeField] | |
bool playAutomatically = true; | |
private void OnEnable() { | |
if (playAutomatically) { | |
CreateAnimationGraph(); | |
playableGraph.Play(); | |
} | |
} | |
void CreateAnimationGraph() { | |
playableGraph = PlayableGraph.Create(); | |
playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); | |
var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent<Animator>()); | |
var clipPlayable = AnimationClipPlayable.Create(playableGraph, modelAnimationClip); | |
playableOutput.SetSourcePlayable(clipPlayable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment