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
Assembly: Unity.XR.Interaction.Toolkit.dll
Syntax
[AddComponentMenu("XR/Lazy Follow", 22)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@3.0/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 |
---|---|
bool |
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 |
---|---|
bool |
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 |
---|---|
float |
maxDistanceAllowed
Maximum distance from target before lazy follow targets, when time threshold is reached.
Declaration
public float maxDistanceAllowed { get; set; }
Property Value
Type | Description |
---|---|
float |
minAngleAllowed
Minimum angle offset (in degrees) from target before which lazy follow starts.
Declaration
public float minAngleAllowed { get; set; }
Property Value
Type | Description |
---|---|
float |
minDistanceAllowed
Minimum distance from target before which a follow lazy follow starts.
Declaration
public float minDistanceAllowed { get; set; }
Property Value
Type | Description |
---|---|
float |
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 |
---|---|
float |
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 |
---|---|
float |
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 |
---|---|
bool |
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 |
---|---|
float |
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 |
---|---|
float |
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 |
---|---|
bool | 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 |
---|---|
bool | Returns true if the angle difference between the current and new target rotations is within the allowed threshold, false otherwise. |