Definition
ScalePrefabInstance(string prefabInstanceName, float XScale, float YScale, float ZScale)
Description
This function scales the transformable prefab instance prefabInstanceName in the X, Y, and Z directions. 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.
XScale, YScale, ZScale
Specifies the scale of the prefab instance prefabInstanceName in the X, Y, and Z directions.
Example 1
scaleX = 1.0 scaleY = 1.0 scaleZ = 1.0 function Init() end function Update() scaleX = scaleX + (GetElapsedTime() * 0.1) scaleY = scaleY + (GetElapsedTime() * 0.2) scaleZ = scaleZ + (GetElapsedTime() * 0.3) if scaleX > 5.0 then scaleX = 1.0 end if scaleY > 5.0 then scaleY = 1.0 end if scaleZ > 5.0 then scaleZ = 1.0 end ScalePrefabInstance("1_VandaEngine17-SamplePack1_well", scaleX, scaleY, scaleZ) end
First, we increase the value of scaleX, scaleY and scaleZ variables according to time and make sure that their value is not more than 5.0 units. Then, using these three values and the ScalePrefabInstance function, we scale 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 ScalePrefabInstance to work.
Example 2
--Name of script is ScalePrefabInstance2.lua scaleX = 1.0 scaleY = 1.0 scaleZ = 1.0 function Init() end function Update() scaleX = scaleX + (GetElapsedTime() * 0.1) scaleY = scaleY + (GetElapsedTime() * 0.2) scaleZ = scaleZ + (GetElapsedTime() * 0.3) if scaleX > 5.0 then scaleX = 1.0 end if scaleY > 5.0 then scaleY = 1.0 end if scaleZ > 5.0 then scaleZ = 1.0 end ScalePrefabInstance("this", scaleX, scaleY, scaleZ) end
If, in the Prefab Editor, you attach ScalePrefabInstance2.lua script to a Prefab, then “this” parameter in the ScalePrefabInstance 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 ScalePrefabInstance function refers to the name instance1_a.
First, we increase the value of scaleX, scaleY and scaleZ variables according to time and make sure that their value is not more than 5.0 units. Then, using these three values and the ScalePrefabInstance function, we scale 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 ScalePrefabInstance to work.
ScalePrefabInstance