Предложить изменения
Успех!
Благодарим вас за то, что вы помогаете нам улучшить качество документации по Unity. Однако, мы не можем принять любой перевод. Мы проверяем каждый предложенный вами вариант перевода и принимаем его только если он соответствует оригиналу.
Закрыть
Ошибка внесения изменений
По определённым причинам предложенный вами перевод не может быть принят. Пожалуйста <a>попробуйте снова</a> через пару минут. И выражаем вам свою благодарность за то, что вы уделяете время, чтобы улучшить документацию по Unity.
Закрыть
Руководство
public static function
Raycast(
origin:
Vector3,
direction:
Vector3,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Vector3 origin,
Vector3 direction,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
origin:
Vector3,
direction:
Vector3,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Vector3 origin,
Vector3 direction,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
origin:
Vector3,
direction:
Vector3,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Vector3 origin,
Vector3 direction,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
origin:
Vector3,
direction:
Vector3,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Vector3 origin,
Vector3 direction,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
Параметры
origin |
The starting point of the ray in world coordinates. |
direction |
@param ray Начальная точка и направление луча. |
maxDistance |
The max distance the ray should check for collisions. |
layerMask |
A Layer mask that is used to selectively ignore Colliders when casting a ray. |
queryTriggerInteraction |
Specifies whether this query should hit Triggers. |
Возврат значений
bool
@return True если луч пересекся хотя-бы с одним коллайдером,в ином случае - false.
Описание
Casts a ray, from point origin
, in direction direction
, of length maxDistance
, against all colliders in the scene.
You may optionally provide a LayerMask, to filter out any Colliders you aren't interested in generating collisions with.
Specifying queryTriggerInteraction
allows you to control whether or not Trigger colliders generate a hit, or whether to use the global Physics.queriesHitTriggers setting.
This example creates a simple Raycast, projecting forwards from the position of the object's current position, extending for 10 units.
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
void FixedUpdate()
{
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, 10))
print("There is something in front of the object!");
}
}
Notes: Raycasts will not detect Colliders for which the Raycast origin is inside the Collider.
If you move Colliders from scripting or by animation, you need to allow at least one FixedUpdate to be executed so that the physics library can update before a Raycast will hit the Collider at its new position.
public static function
Raycast(
origin:
Vector3,
direction:
Vector3,
out
hitInfo:
RaycastHit,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Vector3 origin,
Vector3 direction,
out
RaycastHit hitInfo,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
origin:
Vector3,
direction:
Vector3,
out
hitInfo:
RaycastHit,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Vector3 origin,
Vector3 direction,
out
RaycastHit hitInfo,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
origin:
Vector3,
direction:
Vector3,
out
hitInfo:
RaycastHit,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Vector3 origin,
Vector3 direction,
out
RaycastHit hitInfo,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
origin:
Vector3,
direction:
Vector3,
out
hitInfo:
RaycastHit,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Vector3 origin,
Vector3 direction,
out
RaycastHit hitInfo,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
Параметры
origin |
The starting point of the ray in world coordinates. |
direction |
@param ray Начальная точка и направление луча. |
hitInfo |
If true is returned, hitInfo will contain more information about where the collider was hit (See Also: RaycastHit). |
maxDistance |
The max distance the ray should check for collisions. |
layerMask |
A Layer mask that is used to selectively ignore colliders when casting a ray. |
queryTriggerInteraction |
Specifies whether this query should hit Triggers. |
Возврат значений
bool
@return True если луч пересекся хотя-бы с одним коллайдером,в ином случае - false.
Описание
Casts a ray against all colliders in the scene and returns detailed information on what was hit.
This example reports the distance between the current object and the reported Collider:
using UnityEngine;
public class RaycastExample : MonoBehaviour
{
public Missile missile;
void FixedUpdate()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector3.up, out hit))
print("Found an object - distance: " + hit.distance);
}
}
This example re-introduces the maxDistance
parameter to limit how far ahead to cast the Ray:
using UnityEngine;
public class RaycastExample : MonoBehaviour
{
public Missile missile;
void FixedUpdate()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector3.up, out hit, 100.0f))
print("Found an object - distance: " + hit.distance);
}
}
public static function
Raycast(
ray:
Ray,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Ray ray,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
ray:
Ray,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Ray ray,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
ray:
Ray,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Ray ray,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
ray:
Ray,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Ray ray,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
Параметры
ray |
@param ray Начальная точка и направление луча. |
maxDistance |
The max distance the ray should check for collisions. |
layerMask |
A Layer mask that is used to selectively ignore colliders when casting a ray. |
queryTriggerInteraction |
Specifies whether this query should hit Triggers. |
Возврат значений
bool
@return True если луч пересекся хотя-бы с одним коллайдером,в ином случае - false.
Описание
Same as above using ray.origin
and ray.direction
instead of origin
and direction
.
public static function
Raycast(
ray:
Ray,
out
hitInfo:
RaycastHit,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Ray ray,
out
RaycastHit hitInfo,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
ray:
Ray,
out
hitInfo:
RaycastHit,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Ray ray,
out
RaycastHit hitInfo,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
ray:
Ray,
out
hitInfo:
RaycastHit,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Ray ray,
out
RaycastHit hitInfo,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function
Raycast(
ray:
Ray,
out
hitInfo:
RaycastHit,
maxDistance: float = Mathf.Infinity,
layerMask: int = DefaultRaycastLayers,
queryTriggerInteraction:
QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal):
bool;
public static bool
Raycast(
Ray ray,
out
RaycastHit hitInfo,
float
maxDistance = Mathf.Infinity,
int
layerMask = DefaultRaycastLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
Параметры
ray |
@param ray Начальная точка и направление луча. |
hitInfo |
If true is returned, hitInfo will contain more information about where the collider was hit (See Also: RaycastHit). |
maxDistance |
The max distance the ray should check for collisions. |
layerMask |
A Layer mask that is used to selectively ignore colliders when casting a ray. |
queryTriggerInteraction |
Specifies whether this query should hit Triggers. |
Возврат значений
bool
@return True если луч пересекся хотя-бы с одним коллайдером,в ином случае - false.
Описание
Same as above using ray.origin
and ray.direction
instead of origin
and direction
.
This example draws a line along the length of the Ray whenever a collision is detected: