I am trying to write a script (C#) for a dynamic playlist of moves (think make your own dance). After reading a lot of the forums, I have come to the conclusion, I have no idea if I should use Animator or Animation. The overall play would be:
- User clicks buttons to ‘create a playlist’ of motions on a tablet. (moves[step_L, step_R, jump, step_L, step_right, twirl] )
- User hits play and the clips play on the Oculus.
I feel like it should be simple enough. I am currently using the animator, but can’t figure out how to play specific clips from the animator, and in the documentation I can only find out how to play from the Animator in C#.
I also wouldn’t be opposed to restructuring my approach if someone has a more efficient method.
using UnityEngine;
using System.Collections;
public class anim_Playlist : MonoBehaviour {
public Animator animator;
public AnimationClip[] animPlayList;
int currClip = 0;
//----------------------
//----Start-------------
//----------------------
void Start()
{
// hardcode number of clips in playlist
int numberOfClips = 4;
// create an array the size of the playlist that will later pull from database
string[] dataBase_string;
dataBase_string = new string[numberOfClips];
// hardcode some strings that will eventually be read in from the database
dataBase_string[0] = "crouch-ready"; // should be the hash of this 'state'
dataBase_string[1] = "crouch-set";
dataBase_string[2] = "crouch-run";
dataBase_string[3] = "run";
// get animator
animator = GetComponent<Animator>();
// Go through each clip in the animator
foreach (AnimationClip clip in animator.runtimeAnimatorController.animationClips)
{
// Check the string name against play list from database
foreach (string stringName in dataBase_string) {
if (clip.name == stringName)
{
// if the names are the same, add the clip to the array of anim clips
animPlayList[currClip] = clip;
currClip++;
}
}
}
}
//----------------------
//----Update------------
//----------------------
void Update()
{
// I want to play the playlist when space is pressed
if (Input.GetKeyDown("space"))
{
for (int i = 0; i < 4; i++)
{
//something like this
animPlayList[i].play();
//yield return new WaitForSeconds(anim.clip.length);
}
}
}
}