Skip to content

Instantly share code, notes, and snippets.

@adarapata
Created April 21, 2015 14:50
Show Gist options
  • Select an option

  • Save adarapata/a2a213925d8f8d45bd13 to your computer and use it in GitHub Desktop.

Select an option

Save adarapata/a2a213925d8f8d45bd13 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using UniRx;
public class SkillInput : MonoBehaviour {
public enum SkillType {
Normal,
Charge,
None
}
private Animator animator;
// Use this for initialization
void Start () {
animator = GetComponent<Animator>();
Observable.EveryUpdate()
.Select(_ => GetInputType())
.Where(skill => skill != SkillType.None)
.Subscribe(skill => UpdateAction(skill));
}
private SkillType GetInputType()
{
if(Input.GetKeyDown(KeyCode.Z))
return SkillType.Normal;
else if(Input.GetKeyDown(KeyCode.X))
return SkillType.Charge;
return SkillType.None;
}
private void UpdateAction(SkillType skill)
{
switch(skill){
case SkillType.Normal:
animator.SetTrigger("Normal");
break;
case SkillType.Charge:
animator.SetTrigger("Charge");
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment