Created
February 24, 2016 17:21
-
-
Save tsubaki/d4c6424b3792dbb92878 to your computer and use it in GitHub Desktop.
Raycast、BoxCast、SphereCastの確認用
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 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); | |
} | |
} | |
} |
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 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); | |
} | |
} | |
} |
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 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