Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created February 24, 2016 17:21
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 tsubaki/d4c6424b3792dbb92878 to your computer and use it in GitHub Desktop.
Save tsubaki/d4c6424b3792dbb92878 to your computer and use it in GitHub Desktop.
Raycast、BoxCast、SphereCastの確認用
using UnityEngine;
using System.Collections;
public class BoxcastTest : MonoBehaviour
{
RaycastHit hit;
[SerializeField]
bool isEnable = false;
void OnDrawGizmos()
{
if (isEnable == false)
return;
var scale = transform.lossyScale.x * 0.5f;
var isHit = Physics.BoxCast (transform.position, Vector3.one * scale, transform.forward, out hit, transform.rotation);
if (isHit) {
Gizmos.DrawRay (transform.position, transform.forward * hit.distance);
Gizmos.DrawWireCube (transform.position + transform.forward * hit.distance, Vector3.one * scale * 2);
} else {
Gizmos.DrawRay (transform.position, transform.forward * 100);
}
}
}
using UnityEngine;
using System.Collections;
public class RaycastTest : MonoBehaviour
{
RaycastHit hit;
[SerializeField]
bool isEnable = false;
void OnDrawGizmos()
{
if (isEnable == false)
return;
var scale = transform.lossyScale.x * 0.5f;
var isHit = Physics.Raycast (transform.position, transform.forward, out hit, 100);
if (isHit) {
Gizmos.DrawRay (transform.position, transform.forward * hit.distance);
} else {
Gizmos.DrawRay (transform.position, transform.forward * 100);
}
}
}
using UnityEngine;
using System.Collections;
public class SpherCastTest : MonoBehaviour {
RaycastHit hit;
[SerializeField]
bool isEnable = false;
void OnDrawGizmos()
{
if (isEnable == false)
return;
var radius = transform.lossyScale.x * 0.5f;
var isHit = Physics.SphereCast (transform.position, radius, transform.forward * 10, out hit);
if (isHit) {
Gizmos.DrawRay (transform.position, transform.forward * hit.distance);
Gizmos.DrawWireSphere ( transform.position + transform.forward *( hit.distance ) , radius );
} else {
Gizmos.DrawRay (transform.position, transform.forward * 100);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment