GetDistanceOfPrefabInstanceFromPhysicsCamera

Definition

double GetDistanceOfPrefabInstanceFromPhysicsCamera(string prefabInstanceName)

Description

Returns the distance of the prefab instance prefabInstanceName from the physics camera attached to the main game character.

Parameters

prefabInstanceName
Specifies the name of the prefab instance. You can also use the name “this” for this parameter. In this case, “this” refers to the prefab instance that this script is attached to.

Return Value

Distance of the prefab instance prefabInstanceName from the physics camera attached to the main game character.

Example 1

distance = 0.0

function Init()
    distance = GetDistanceOfPrefabInstanceFromPhysicsCamera("1_VandaEngine17-SamplePack1_well")

    message = string.format("\nDistance is > %.2f" , distance )
    PrintConsole(message)
end

function Update()

end
Returns the distance of prefab instance “1_VandaEngine17-SamplePack1_well” from the physics camera attached to the main game character. Then we print the return value of this function using PrintConsole function.

Example 2

--name of script is GetDistanceOfPrefabInstanceFromPhysicsCamera2.lua

distance = 0.0

function Init()
    distance = GetDistanceOfPrefabInstanceFromPhysicsCamera("this")

    message = string.format("\nDistance is > %.2f" , distance )
    PrintConsole(message)
end

function Update()

end
If, in the Prefab Editor, you attach GetDistanceOfPrefabInstanceFromPhysicsCamera2.lua script to a Prefab, then “this” parameter in the GetDistanceOfPrefabInstanceFromPhysicsCamera function will point to instances of that Prefab in current VScene. For example, if you have an Instance named instance1_a from a Prefab named to which this script is attached, “this” in GetDistanceOfPrefabInstanceFromPhysicsCamera function refers to the name instance1_a.
In this case, GetDistanceOfPrefabInstanceFromPhysicsCamera function returns the distance of prefab instance instance1_a from the physics camera attached to the main game character. Then we print the return value of this function using PrintConsole function.
adminGetDistanceOfPrefabInstanceFromPhysicsCamera