Skip to content

Instantly share code, notes, and snippets.

@gkagm2
Created April 17, 2019 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkagm2/ae87c60c5f8b8d199df030fb74092e12 to your computer and use it in GitHub Desktop.
Save gkagm2/ae87c60c5f8b8d199df030fb74092e12 to your computer and use it in GitHub Desktop.
RayCast 예제 코드
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