Skip to content

Instantly share code, notes, and snippets.

@sugimotoak
Created December 22, 2013 16:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sugimotoak/8085190 to your computer and use it in GitHub Desktop.
Save sugimotoak/8085190 to your computer and use it in GitHub Desktop.
Unity+OculusRift+LeapMotionで3Dキャラクターに触れる ref: http://qiita.com/sugimotoak/items/1d3574a5a084d0c349cd
using UnityEngine;
using System.Collections;
public class AnimationScript : MonoBehaviour {
public GameObject miku = null;
private Animation mikuAnime;
// Use this for initialization
void Start () {
if (miku == null)
return;
mikuAnime = miku.GetComponent<Animation>();
}
// Update is called once per frame
void Update () {
}
public void touch(AnimationClip clip) {
mikuAnime[clip.name].wrapMode = WrapMode.Once;
mikuAnime[clip.name].layer = 2;
mikuAnime.CrossFade(clip.name);
}
}
public AnimationClip animationClip = null;
private GameObject controller = null;
private float timer = 0.0f;
// Use this for initialization
void Start () {
controller = GameObject.Find("Controller");
}
// Update is called once per frame
void Update () {
if (timer > 0)
timer -= Time.deltaTime;
}
private void OnCollisionEnter(Collision collision) {
if (animationClip == null)
return;
if (timer > 0)
return;
if (collision.gameObject.CompareTag("FingerTip")) {
controller.SendMessage("touch",animationClip);
timer = animationClip.length;
}
}
using UnityEngine;
using System.Collections;
public class TouchMessage : MonoBehaviour {
public AnimationClip animationClip = null;
private GameObject controller = null;
private float timer = 0.0f;
// Use this for initialization
void Start () {
controller = GameObject.Find("Controller");
}
// Update is called once per frame
void Update () {
if (timer > 0)
timer -= Time.deltaTime;
}
private void OnCollisionEnter(Collision collision) {
if (animationClip == null)
return;
if (timer > 0)
return;
if (collision.gameObject.CompareTag("FingerTip")) {
controller.SendMessage("touch",animationClip);
timer = animationClip.length;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment