Created
April 17, 2019 08:23
-
-
Save gkagm2/ae87c60c5f8b8d199df030fb74092e12 to your computer and use it in GitHub Desktop.
RayCast 예제 코드
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class RayCastEx : MonoBehaviour { | |
void OnCreate() { } | |
void OnUpdate() { } | |
void OnDrawGizmos() | |
{ | |
float maxDistance = 100; | |
RaycastHit hit; | |
// Physics.Raycast (레이저를 발사할 위치, 발사 방향, 충돌 결과, 최대 거리) | |
bool isHit = Physics.Raycast(transform.position, transform.forward, out hit, maxDistance); | |
Gizmos.color = Color.red; | |
if (isHit) | |
{ | |
Gizmos.DrawRay(transform.position, transform.forward * hit.distance); | |
} | |
else | |
{ | |
Gizmos.DrawRay(transform.position, transform.forward * maxDistance); | |
} | |
} | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment