GetPrefabInstanceTranslate

Definition

double,double,double GetPrefabInstanceTranslate(string prefabInstanceName)

Description

This function receives the name of the prefab instance prefabInstanceName and returns its position as three values x, y and z.

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

This function returns the prefab instance position as three values x, y and z.

Example 1

posX = 0.0
posY = 0.0
posZ = 0.0

function Init()
    posX, posY, posZ = GetPrefabInstanceTranslate("1_VandaEngine17-SamplePack1_well")

    message = string.format("\nPrefab instance position is > (%.2f, %.2f, %.2f)" , posX, posY, posZ)
    PrintConsole(message)
end

function Update()

end
First, GetPrefabInstanceTranslate function returns the position of “1_VandaEngine17-SamplePack1_well”. Then we display the position values in the console using the PrintConsole function.

Example 2

--Name of script is GetPrefabInstanceTranslate2.lua

posX = 0.0
posY = 0.0
posZ = 0.0

function Init()
    posX, posY, posZ = GetPrefabInstanceTranslate("this")

    message = string.format("\nPrefab instance position is > (%.2f, %.2f, %.2f)" , posX, posY, posZ)
    PrintConsole(message)
end

function Update()

end
If, in the Prefab Editor, you attach GetPrefabInstanceTranslate2.lua script to a Prefab, then “this” parameter in the GetPrefabInstanceTranslate 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 GetPrefabInstanceTranslate function refers to the name instance1_a.
In this example, GetPrefabInstanceTranslate function returns the position of current prefab instance (for example, instance1_a). Then we display the position values in the console using the PrintConsole function.
adminGetPrefabInstanceTranslate