Created
December 22, 2013 16:43
-
-
Save sugimotoak/8085190 to your computer and use it in GitHub Desktop.
Unity+OculusRift+LeapMotionで3Dキャラクターに触れる ref: http://qiita.com/sugimotoak/items/1d3574a5a084d0c349cd
This file contains 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; | |
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); | |
} | |
} |
This file contains 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
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; | |
} | |
} |
This file contains 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; | |
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