Created
January 19, 2016 10:43
-
-
Save peroon/15a68ab84416de7c654d 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; | |
| // カメラからレイを飛ばす | |
| public class RayShooter : MonoBehaviour { | |
| public LayerMask hitLayerMask; // レイ判定するオブジェクトは限定する | |
| public float rayLength = 20.0f; | |
| private Ray ray; | |
| private RaycastHit raycastHit; | |
| void Update () { | |
| // Debug Line | |
| Debug.DrawLine(transform.position, transform.position + transform.forward * rayLength, Color.red); | |
| // 毎フレーム、向きに応じてレイを作る | |
| ray = new Ray(transform.position, transform.forward); | |
| // ヒットしたオブジェクトのイベントを呼ぶ | |
| if (Physics.Raycast (ray, out raycastHit, rayLength, hitLayerMask)) { | |
| //Debug.Log(raycastHit.collider.name); | |
| raycastHit.collider.SendMessage("OnRayHit"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment