Last active
August 29, 2015 14:22
-
-
Save komo91/c2280c0fddcd3afda20d 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; | |
//MonoBehaviourを継承したPointigHandlerクラスの宣言 | |
public class PointingHandler : MonoBehaviour { | |
//メンバーフィールドの宣言 | |
public float distance = 20; //判定範囲 | |
public GameObject ElbowRight; //右ひじ | |
public GameObject WristRight; //右手首 | |
public GameObject ElbowLeft; //左ひじ | |
public GameObject WristLeft; //左手首 | |
public LayerMask layerMask; //背景部分 | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
// 肘->手首 ベクトル (RAY) を算出 | |
Ray rayRight = new Ray(WristRight.transform.position, WristRight.transform.position - ElbowRight.transform.position); | |
Ray rayLeft = new Ray(WristLeft.transform.position, WristLeft.transform.position - ElbowLeft.transform.position); | |
// 上記RAYがぶつかるオブジェクトを探索 | |
FindAndPaint(rayRight); //FindAndPaintメソッドを呼び出し | |
FindAndPaint(rayLeft); //FindAndPaintメソッドを呼び出し | |
} | |
void FindAndPaint(Ray ray) | |
{ | |
// ヒットした際の情報を格納するRaycastHitオブジェクト | |
RaycastHit hit; | |
// 腕差しベクトル、結果を収めるRaycastHitオブジェクト、判定範囲、レイヤーマスク | |
if (Physics.Raycast(ray, out hit, distance, layerMask)) | |
{ | |
// ヒットしたオブジェクトを特定して、色を付ける | |
hit.transform.gameObject.GetComponent<PaintIt>().setColor(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment