Definition
RotatePrefabInstance(string prefabInstanceName, float XRotationAngle, float YRotationAngle, float ZRotationAngle)
Description
This function rotates the transformable prefab instance prefabInstanceName around the X, Y, and Z axes. 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.
XRotationAngle, YRotationAngle, ZRotationAngle
Specifies the rotation of the prefab instance prefabInstanceName around the X, Y, and Z axes.
Example 1
rotateX = 0.0 rotateY = 0.0 rotateZ = 0.0 function Init() end function Update() rotateX = rotateX + GetElapsedTime() rotateY = rotateY + (GetElapsedTime() * 2.0) rotateZ = rotateZ + (GetElapsedTime() * 3.0) if rotateX > 360.0 then rotateX = rotateX - 360.0 end if rotateY > 360.0 then rotateY = rotateY - 360.0 end if rotateZ > 360.0 then rotateZ = rotateZ - 360.0 end RotatePrefabInstance("1_VandaEngine17-SamplePack1_well", rotateX, rotateY, rotateZ) end
First, we increase the value of rotateX, rotateY and rotateZ variables according to time and make sure that their value is not more than 360.0 degrees. Then, using these three values and the RotatePrefabInstance function, we rotate the prefab instance 1_VandaEngine17-SamplePack1_well around the X, Y and Z axes. It should be noted that the Transformable feature of prefab instance 1_VandaEngine17-SamplePack1_well must be enabled for the function RotatePrefabInstance to work.
Example 2
--Name of script is RotatePrefabInstance2.lua rotateX = 0.0 rotateY = 0.0 rotateZ = 0.0 function Init() end function Update() rotateX = rotateX + GetElapsedTime() rotateY = rotateY + (GetElapsedTime() * 2.0) rotateZ = rotateZ + (GetElapsedTime() * 3.0) if rotateX > 360.0 then rotateX = rotateX - 360.0 end if rotateY > 360.0 then rotateY = rotateY - 360.0 end if rotateZ > 360.0 then rotateZ = rotateZ - 360.0 end RotatePrefabInstance("this", rotateX, rotateY, rotateZ) end
If, in the Prefab Editor, you attach RotatePrefabInstance2.lua script to a Prefab, then “this” parameter in the RotatePrefabInstance 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 RotatePrefabInstance function refers to the name instance1_a.
First, we increase the value of rotateX, rotateY and rotateZ variables according to time and make sure that their value is not more than 360.0 degrees. Then, using these three values and the RotatePrefabInstance function, we rotate the current prefab instance (for example, instance1_a) around the X, Y and Z axes. It should be noted that the Transformable feature of current prefab instance must be enabled for the function RotatePrefabInstance to work.
RotatePrefabInstance