Here are the examples of the csharp api UnityEngine.Debug.DrawRay(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Color, float) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
5 Examples
19
View Source File : AvatarBehavior.cs
License : MIT License
Project Creator : Daimler
License : MIT License
Project Creator : Daimler
void Update()
{
///Handle the walk command on mouse click
if (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButtonDown(0))
{
Vector3 mousePos = Input.mousePosition;
Ray mouseRay = Camera.main.ScreenPointToRay(mousePos);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(mouseRay, out hit, 10000))
{
//Ray for visual guide from camera to mouse position.
Debug.DrawRay(mouseRay.origin, mouseRay.direction * hit.distance, Color.red, 1);
GameObject walkTarget = GameObject.Find("WalkTarget");
walkTarget.transform.position = new Vector3(hit.point.x, walkTarget.transform.position.y, hit.point.z);
walkTarget.GetComponent<MMISceneObject>().UpdateTransform();
MInstruction walkInstruction = new MInstruction(MInstructionFactory.GenerateID(), "Walk", "Locomotion/Walk")
{
Properties = PropertiesCreator.Create("TargetName", "WalkTarget", "UseTargetOrientation", false.ToString())
};
MInstruction idleInstruction = new MInstruction(MInstructionFactory.GenerateID(), "Idle", "Pose/Idle")
{
//Start idle after walk has been finished
StartCondition = walkInstruction.ID + ":" + mmiConstants.MSimulationEvent_End //synchronization constraint similar to bml "id:End" (bml original: <bml start="id:End"/>
};
//Abort all current tasks
this.CoSimulator.Abort();
MSimulationState currentState = new MSimulationState() { Initial = this.avatar.GetPosture(), Current = this.avatar.GetPosture() };
//replacedign walk and idle instruction
this.CoSimulator.replacedignInstruction(walkInstruction, currentState);
this.CoSimulator.replacedignInstruction(idleInstruction, currentState);
}
}
}
19
View Source File : EarthquakeSelector.cs
License : MIT License
Project Creator : SmallPlanet
License : MIT License
Project Creator : SmallPlanet
void Update()
{
if(Input.GetButtonDown("Jump")) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Debug.DrawRay(ray.origin, ray.direction, Color.green, 10f);
if (Physics.Raycast(ray, out hit, 100.0f, LayerMask.GetMask("Location"))) {
if(hit.collider != null) {
UpdateSelectedPoint(hit.collider.gameObject);
var eqPoint = hit.collider.gameObject.GetComponent<EarthquakePoint>();
DisplayEarthquakeInfo(eqPoint);
}
} else {
UpdateSelectedPoint(null);
DisplayEarthquakeInfo(null);
}
}
}
19
View Source File : PlaneSelector.cs
License : MIT License
Project Creator : SmallPlanet
License : MIT License
Project Creator : SmallPlanet
void Update() {
if (Input.GetButtonDown("Jump")) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Debug.DrawRay(ray.origin, ray.direction, Color.green, 10f);
if (Physics.Raycast(ray, out hit, 100.0f, LayerMask.GetMask("Location"))) {
if (hit.collider != null) {
UpdateSelectedPoint(hit.collider.gameObject);
var airplane = hit.collider.gameObject.GetComponent<Airplane_Realtime>();
DisplayFlightInfo(airplane.info);
}
}
else {
UpdateSelectedPoint(null);
DisplayFlightInfo(null);
}
}
}
19
View Source File : PlanetUtility.cs
License : MIT License
Project Creator : SmallPlanet
License : MIT License
Project Creator : SmallPlanet
public static RaycastHit? LineFromOriginToSurface(Transform planet, Vector3 line, LayerMask mask) {
//Need to reverse the ray direction because collisions don't work from the inside of a collider
//So take a point some distance along the line as origin, then reverse the direction
//Also, planet can't be larger than 200 units
var ray = new Ray(planet.position, line * 200.0f);
ray.origin = ray.GetPoint(200.0f);
ray.direction = -ray.direction;
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 200.0f, mask)) { return hit; }
else {
Debug.Log("Raycast missed Planet - Please ensure you're object is set to a 'Planet' layer.");
Debug.DrawRay(ray.origin, ray.direction * 200.0f, Color.yellow, 1000.0f);
}
return null;
}
19
View Source File : DistanceGrabber.cs
License : MIT License
Project Creator : Tobbse
License : MIT License
Project Creator : Tobbse
protected bool FindTarget(out DistanceGrabbable dgOut, out Collider collOut)
{
dgOut = null;
collOut = null;
float closestMagSq = float.MaxValue;
// First test for objects within the grab volume, if we're using those.
// (Some usage of DistanceGrabber will not use grab volumes, and will only
// use spherecasts, and that's supported.)
foreach (OVRGrabbable cg in m_grabCandidates.Keys)
{
DistanceGrabbable grabbable = cg as DistanceGrabbable;
bool canGrab = grabbable != null && grabbable.InRange && !(grabbable.isGrabbed && !grabbable.allowOffhandGrab);
if (!canGrab)
{
continue;
}
for (int j = 0; j < grabbable.grabPoints.Length; ++j)
{
Collider grabbableCollider = grabbable.grabPoints[j];
// Store the closest grabbable
Vector3 closestPointOnBounds = grabbableCollider.ClosestPointOnBounds(m_gripTransform.position);
float grabbableMagSq = (m_gripTransform.position - closestPointOnBounds).sqrMagnitude;
if (grabbableMagSq < closestMagSq)
{
bool accept = true;
if(m_preventGrabThroughWalls)
{
// NOTE: if this raycast fails, ideally we'd try other rays near the edges of the object, especially for large objects.
// NOTE 2: todo optimization: sort the objects before performing any raycasts.
Ray ray = new Ray();
ray.direction = grabbable.transform.position - m_gripTransform.position;
ray.origin = m_gripTransform.position;
RaycastHit obstructionHitInfo;
Debug.DrawRay(ray.origin, ray.direction, Color.red, 0.1f);
if (Physics.Raycast(ray, out obstructionHitInfo, m_maxGrabDistance, 1 << m_obstructionLayer))
{
float distToObject = (grabbableCollider.ClosestPointOnBounds(m_gripTransform.position) - m_gripTransform.position).magnitude;
if(distToObject > obstructionHitInfo.distance * 1.1)
{
accept = false;
}
}
}
if(accept)
{
closestMagSq = grabbableMagSq;
dgOut = grabbable;
collOut = grabbableCollider;
}
}
}
}
if (dgOut == null && m_useSpherecast)
{
return FindTargetWithSpherecast(out dgOut, out collOut);
}
return dgOut != null;
}