Skip to content

Instantly share code, notes, and snippets.

@kenjiSpecial
Created February 5, 2017 14:55
Show Gist options
  • Select an option

  • Save kenjiSpecial/c20ac6d6f8de378d9deb30d4293187d0 to your computer and use it in GitHub Desktop.

Select an option

Save kenjiSpecial/c20ac6d6f8de378d9deb30d4293187d0 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HandController : MonoBehaviour {
public Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
AnimatorStateInfo currentState = anim.GetCurrentAnimatorStateInfo(0);
float playbackTime = currentState.normalizedTime; // % 1;
float rate = 0f;
if(currentState.IsName("Normal")) {
rate = 0f;
}
if (currentState.IsName("Grab_001")) {
if (playbackTime > 1.0f) rate = 0.0f;
else {
rate = 1.0f - playbackTime;
}
}
if (currentState.IsName("Grab_002")) {
if (playbackTime > 1.0f) rate = 0.0f;
else {
rate = 1.0f - playbackTime;
}
}
if (Input.GetMouseButtonDown(0)) {
anim.Play("Grab_001", -1, rate);
}
if (Input.GetMouseButtonUp(0)){
anim.Play("Grab_002", -1, rate);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment