Created
April 21, 2015 14:50
-
-
Save adarapata/a2a213925d8f8d45bd13 to your computer and use it in GitHub Desktop.
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 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