Definition
TranslatePrefabInstance(string prefabInstanceName, float XPosition, float YPosition, float ZPosition)
Description
This function moves the transformable prefab instance prefabInstanceName to the (X, Y, Z) position. For this function to work, in prefab mode, through the Modify > Prefab Properties menu, make sure the Transformable option is checked for the desired prefab.
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.
XPosition, YPosition, ZPosition
Specify the X, Y and Z components of 3D position of the prefab instance prefabInstanceName.
Example 1
translateX = 0.0 translateY = 0.0 translateZ = 0.0 function Init() end function Update() translateX = translateX + (GetElapsedTime() * 0.1) translateY = translateY + (GetElapsedTime() * 0.2) translateZ = translateZ + (GetElapsedTime() * 0.3) if translateX > 5.0 then translateX = 0.0 end if translateY > 5.0 then translateY = 0.0 end if translateZ > 5.0 then translateZ = 0.0 end TranslatePrefabInstance("1_VandaEngine17-SamplePack1_well", translateX, translateY, translateZ) end
First, we increase the value of translateX, translateY and translateZ variables according to time and make sure that their value is not more than 5.0 units. Then, using these three values and the TranslatePrefabInstance function, we translate the prefab instance 1_VandaEngine17-SamplePack1_well in the X, Y and Z directions. It should be noted that the Transformable property of prefab instance 1_VandaEngine17-SamplePack1_well must be enabled for the function TranslatePrefabInstance to work.
Example 2
--Name of script is TranslatePrefabInstance2.lua translateX = 0.0 translateY = 0.0 translateZ = 0.0 function Init() end function Update() translateX = translateX + (GetElapsedTime() * 0.1) translateY = translateY + (GetElapsedTime() * 0.2) translateZ = translateZ + (GetElapsedTime() * 0.3) if translateX > 5.0 then translateX = 0.0 end if translateY > 5.0 then translateY = 0.0 end if translateZ > 5.0 then translateZ = 0.0 end TranslatePrefabInstance("this", translateX, translateY, translateZ) end
If, in the Prefab Editor, you attach TranslatePrefabInstance2.lua script to a Prefab, then “this” parameter in the TranslatePrefabInstance 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 a to which this script is attached, “this” in TranslatePrefabInstance function refers to the name instance1_a.
First, we increase the value of translateX, translateY and translateZ variables according to time and make sure that their value is not more than 5.0 units. Then, using these three values and the TranslatePrefabInstance function, we translate the current prefab instance (for example, instance1_a) in the X, Y and Z directions. It should be noted that the Transformable property of current prefab instance must be enabled for the function TranslatePrefabInstance to work.
TranslatePrefabInstance