Class LazyFollow
Makes the GameObject this component is attached to follow a target with a delay and some other layout options.
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit.UI
Syntax
[AddComponentMenu("XR/Lazy Follow", 22)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.4/api/UnityEngine.XR.Interaction.Toolkit.UI.LazyFollow.html")]
public class LazyFollow : MonoBehaviour
Properties
applyTargetInLocalSpace
If true, apply the target offset in local space. If false, apply the target offset in world space.
Declaration
public bool applyTargetInLocalSpace { get; set; }
Property Value
| Type | Description |
|---|---|
| Boolean |
followInLocalSpace
If true, read the local transform of the target to lazy follow, otherwise read the world transform. If using look at rotation follow modes, only world-space follow is supported.
Declaration
public bool followInLocalSpace { get; set; }
Property Value
| Type | Description |
|---|---|
| Boolean |
maxAngleAllowed
Maximum angle offset (in degrees) from target before lazy follow targets, when time threshold is reached
Declaration
public float maxAngleAllowed { get; set; }
Property Value
| Type | Description |
|---|---|
| Single |
maxDistanceAllowed
Maximum distance from target before lazy follow targets, when time threshold is reached.
Declaration
public float maxDistanceAllowed { get; set; }
Property Value
| Type | Description |
|---|---|
| Single |
minAngleAllowed
Minimum angle offset (in degrees) from target before which lazy follow starts.
Declaration
public float minAngleAllowed { get; set; }
Property Value
| Type | Description |
|---|---|
| Single |
minDistanceAllowed
Minimum distance from target before which a follow lazy follow starts.
Declaration
public float minDistanceAllowed { get; set; }
Property Value
| Type | Description |
|---|---|
| Single |
movementSpeed
Movement speed used when smoothing to new target. Lower values mean the lazy follow lags further behind the target.
Declaration
public float movementSpeed { get; set; }
Property Value
| Type | Description |
|---|---|
| Single |
movementSpeedVariancePercentage
Adjust movement speed based on distance from the target using a tolerance percentage. 0% for constant speed. For example, with a variance of 25% (0.25), and a speed of 6, the upper bound is 7.5, which is reached as the target is approached. If the target is far from the object, the speed will trend toward the lower bound, which would be 4.5 in this case.
Declaration
public float movementSpeedVariancePercentage { get; set; }
Property Value
| Type | Description |
|---|---|
| Single |
positionFollowMode
Determines the follow mode used to determine a new rotation.
Declaration
public LazyFollow.PositionFollowMode positionFollowMode { get; set; }
Property Value
| Type | Description |
|---|---|
| LazyFollow.PositionFollowMode |
rotationFollowMode
Determines the follow mode used to determine a new rotation.
Declaration
public LazyFollow.RotationFollowMode rotationFollowMode { get; set; }
Property Value
| Type | Description |
|---|---|
| LazyFollow.RotationFollowMode |
snapOnEnable
Snap to target position when this component is enabled.
Declaration
public bool snapOnEnable { get; set; }
Property Value
| Type | Description |
|---|---|
| Boolean |
target
The object being followed. If not set, this will default to the main camera when this component is enabled.
Declaration
public Transform target { get; set; }
Property Value
| Type | Description |
|---|---|
| Transform |
targetOffset
The amount to offset the target's position when following. This position is relative/local to the target object.
Declaration
public Vector3 targetOffset { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
timeUntilThresholdReachesMaxAngle
Time required to elapse (in seconds) before the max angle offset allowed goes from the min angle offset to the max.
Declaration
public float timeUntilThresholdReachesMaxAngle { get; set; }
Property Value
| Type | Description |
|---|---|
| Single |
timeUntilThresholdReachesMaxDistance
The time threshold (in seconds) where if max distance is reached the lazy follow capability will not be turned off.
Declaration
public float timeUntilThresholdReachesMaxDistance { get; set; }
Property Value
| Type | Description |
|---|---|
| Single |
Methods
Awake()
See MonoBehaviour.
Declaration
protected void Awake()
LateUpdate()
See MonoBehaviour.
Declaration
protected void LateUpdate()
OnDestroy()
See MonoBehaviour.
Declaration
protected void OnDestroy()
OnDisable()
See MonoBehaviour.
Declaration
protected void OnDisable()
OnEnable()
See MonoBehaviour.
Declaration
protected void OnEnable()
OnValidate()
See MonoBehaviour.
Declaration
protected void OnValidate()
TryGetThresholdTargetPosition(out Vector3)
Determines if the new target position is within a dynamically determined threshold based on the time since the last update, and outputs the new target position if it meets the threshold.
Declaration
protected virtual bool TryGetThresholdTargetPosition(out Vector3 newTarget)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | newTarget | The output new target position as a Vector3, if within the allowed threshold. |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if the squared distance between the current and new target positions is within the allowed threshold, false otherwise. |
TryGetThresholdTargetRotation(out Quaternion)
Determines if the new target rotation is within a dynamically determined threshold based on the time since the last update, and outputs the new target rotation if it meets the threshold.
Declaration
protected virtual bool TryGetThresholdTargetRotation(out Quaternion newTarget)
Parameters
| Type | Name | Description |
|---|---|---|
| Quaternion | newTarget | The output new target rotation as a Quaternion, if within the allowed threshold. |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if the angle difference between the current and new target rotations is within the allowed threshold, false otherwise. |